3

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?

NewJoizey
  • 73
  • 11
  • Are you using the old xaml build or the new vNext build? – Cece Dong - MSFT Jun 24 '16 at 06:38
  • Are you able to run the project with MSBuild manually on build agent machine? Is there more error message? Have you checked whether the path is valid on your build agent machine? – Cece Dong - MSFT Jun 24 '16 at 07:46
  • I am using the new vNext build, and I whether I try to run manually or allow CI to trigger the build the error message is the same, the exact syntax of which is: 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" exited with code 1. Unexpected exit code received from msbuild.exe: 1 I verified that all the paths exist/there are no spelling errors. I think it may have something to do with mklink needing "run as administrator" rights to create a symlink. Is there any way to mask a in MSBuild? – NewJoizey Jun 24 '16 at 14:23

1 Answers1

3

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

NewJoizey
  • 73
  • 11