Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using mklink command inside an MSBuild PostBuildEvent in TFS

My .csproj defines the following post build event in the .csproj file that regenerates a symbolic link. This works fine inside with a manual Visual Studio build and the symlink gets regenerated without issue:

 <PostBuildEvent>
  del C:\foo\foo\bin\debug\my.config
  mklink C:\bar\bar\bar\bar\bar\bar\bin\debug\my.config c:\baz\baz\my.config  
</PostBuildEvent>

However, I am trying to set up continuous integration using TFS2015 with automated builds using MSBuild, however in this case, the build fails with 'the command mklink C:\bar\bar\bar\bar\bar\bar\bin\debug\my.config c:\baz\baz\my.config exited with code 1'.

How do I go about regenerating a symbolic link via an automated build?

like image 831
NewJoizey Avatar asked May 18 '26 01:05

NewJoizey


1 Answers

I resolved this by setting the variable $(BuildingInsideVisualStudio) to true inside my csproj file in the following way:

<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
    <PostBuildEvent>
       del C:\foo\foo\bin\debug\my.config
       mklink C:\bar\bar\bar\bar\bar\bar\bin\debug\my.config c:\baz\baz\my.config  
    </PostBuildEvent>
</PropertyGroup>

I had seen this as a possible answer elsewhere, however the posts I saw showed incorrect syntax and did not clearly illustrate how to use the variable within the context of the csproj build script. Hopefully this will clarify for someone.

This MSDN article was useful: https://msdn.microsoft.com/en-us/library/ms171468(v=vs.140).aspx

like image 92
NewJoizey Avatar answered May 20 '26 18:05

NewJoizey