“Access is denied” on build server when deploying

2019-03-24 14:28发布

问题:

In order to generate XML documentation using Web API Help Pages for my Web API project, I had to check the "XML documentation file" option under the "Builds" section of my project's properties. This correctly generates the documentation when I build locally.

However, when I check in, I get the following error on the build server:

CSC: Error generating XML documentation file 'c:\Builds\3...\Sources\CurrentVersion...\ProjectName\App_Data\XmlDocument.xml' ('Access is denied. ')

I'm not sure why this happens, since it creates a new directory for each build anyway. I googled this issue and searched Stack Overflow, but the only solutions I found were to remove the XML documentation file (which defeats the purpose of using Web API Help Pages). How can I resolve this?

回答1:

If the XML file is checked-in to TFS then when TFS gets the files to the workspace on the build server, it will have "Read-Only attribute" associated with the file. Now when the build generates the new XML file, it wont be able to overwrite the old XML file since it has the read-only attribute.

Solution is to: a) use your build scripts to modify the file attribute and make it read-write b) remove the xml file checked-in to TFS so that, build will be able to generate the XML easily.

Update: if you are using solution b, if the file is part of you project file make sure that you remove the file from the csproj file as well.



回答2:

Removing the file from Source Control did not fix it for me, Team Server was still trying to access it.

I was able to solve it by Cloaking App_Data in the build definition.



回答3:

Even though you are creating a new directory for each build, this directory is only for build output. The build doesn't actually occur in that directory, it occurs in the server's tfs workspace and the build output get's copied into the new directory after. The access denied error is due to the checked in file being read only when accessed by tfs on the build server work space and so the file cannot be re-generated\ overwritten during build.

I got around this issue by changing my xml documentation output path to the bin folder.

So Project-> Build -> Output Output path: bin\ XML Documentation file: bin/XmlDocument.xml

I suggest you do this for all of your build configurations (Project -> Build, Configuration Drop down menu -> Select All Configurations)

Then under Project -> Areas/ HelpPage/App_Start/HelpPageConfig.cs change config.SetDocumentationProvider to map to "~/bin/XmlDocument.xml"

Don't forget to remove the XmlDocument.xml file from source control as well since it is re-generated for every build