Could not access app.config because it is being used by another process.

Hi, I'm trying to build my application on Teamcity. For build purposes I'm using transformations for app.config (app.Debug.config, app.Release.config) and have a target in my .csproj file:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
    <TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="App.config" StackTrace="true" />
</Target>

In configuration steps I'm using following parameters:

 

But I'm receiving an error during the build:

 

Exception: Could not write Destination file: The process cannot access the file 'D:\Bin\TeamCity\buildAgent\work\a9dace5129813016\ITServerApplication\App.config' because it is being used by another process. at Microsoft.Web.Publishing.Tasks.TransformXml.SaveTransformedFile(XmlTransformableDocument document, String destinationFile) at Microsoft.Web.Publishing.Tasks.TransformXml.Execute() IOException: The process cannot access the file 'D:\Bin\TeamCity\buildAgent\work\a9dace5129813016\ITServerApplication\App.config' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) at Microsoft.Web.Publishing.Tasks.XmlAttributePreservingWriter..ctor(String fileName, Encoding encoding) at Microsoft.Web.Publishing.Tasks.XmlFileInfoDocument.Save(String filename) at Microsoft.Web.Publishing.Tasks.TransformXml.SaveTransformedFile(XmlTransformableDocument document, String destinationFile)

 

It looks like my app.config that should be rewritten by transform xml somehow became locked.

Could you be so kind and tell me where I'm wrong? Thank you in advance.

0
3 comments
Official comment

Hi
Try changing the name of the destination file, for instance `Destination="App2.config"`

Hi Vasiliy,

which version of teamcity are you using? Usual culprits for files being locked are antivirus software and backup applications, but in this case, it might be that the msbuild process is picking up the file and not releasing it or allowing it to be changed, so it would be important to understand which version you are using. It would also be helpful if you could try the last one, but if not, we might be able to figure it out.

0
Avatar
Permanently deleted user

Hi Denis,

I'm using TeamCity Professional 2017.1.4 (build 47070).

Antivirus doesn't affect this file because in other conditions (without transformations) it works properly (when changing some strings inside of .config file via CMD)

0

Please sign in to leave a comment.