SolutionDir set to *Undefined* in post-build xcopy event
Asked Answered
B

3

13

I have a project that has a post-build event that xcopies a DLLs to a certain directory:

xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y
xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y

However, I have CruiseControl.NET set up as a build server and MSBuild is failing on building that project due to this xcopy post-build event:

MSB3073: The command "xcopy "C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.dll" "*Undefined*..\UdpLocationService\bin\Plugins\" /d /y xcopy "C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.pdb" "*Undefined*..\UdpLocationService\bin\Plugins\" /d /y" exited with code 4. in Microsoft.Common.targets(3397, 13)

Any suggestions to get this fixed?

Borstal answered 1/7, 2010 at 19:56 Comment(0)
D
4

Follow these steps:

  • Unload your project file (e.g. *.csproj)
  • Open your project file for editing
  • Find the AfterBuild target
  • Separate out the two invocations of XCopy into two distinct Exec tasks
  • Save your changes and Reload your project file
Depilate answered 1/7, 2010 at 20:1 Comment(3)
Thanks, that fixed the first error but not the second: MSB3073: The command "xcopy "C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.pdb" "Undefined..\UdpLocationService\bin\Plugins\" /d /y" exited with code 4. in Microsoft.Common.targets(3397, 13)Borstal
I should also add that there is no AfterBuild or exec in the csproj file. This is what it looks like: <PropertyGroup> <PostBuildEvent>xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y</PostBuildEvent> <PostBuildEvent>xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y</PostBuildEvent> </PropertyGroup>Borstal
What version of Visual Studio are you using?Depilate
C
31

I just ran into the same problem with TeamCity.

The issue here is the $(SolutionDir) property in your build file. You haven't defined it in your call to MsBuild (this is why you see the word undefined in your output).

Call msbuild with the property set, like this:

msbuild myproject.csproj /property:SolutionDir="solution directory"\

Where "solution directory" is the directory containing your solution file. Note the trailing slash, you'll need that to make sure the path is correctly formed.

Caines answered 15/2, 2012 at 18:11 Comment(1)
or you can include the trailing slash inside the double quotes - just remember to escape it with another backslash. So in my case, the call would be msbuild myproject.csproj /property:SolutionDir="%teamcity.build.checkoutdir%\\"Bludge
P
8

I fixed this for problems with the Microsoft.SqlServer.Compact nuget package (which adds a similar post-build script), by adding:

<SolutionDir Condition="'$(SolutionDir)'=='' or '$(SolutionDir)'=='*Undefined*'">..\</SolutionDir>

right above the <PostBuildEvent>. You'll want to adjust the relative path to match your project layout.

Permeability answered 9/8, 2013 at 17:53 Comment(1)
This error can occur when building a project instead of a solution. When this happens, $(SolutionDir) is in fact undefined and the solution above gets around the limitation.Chil
D
4

Follow these steps:

  • Unload your project file (e.g. *.csproj)
  • Open your project file for editing
  • Find the AfterBuild target
  • Separate out the two invocations of XCopy into two distinct Exec tasks
  • Save your changes and Reload your project file
Depilate answered 1/7, 2010 at 20:1 Comment(3)
Thanks, that fixed the first error but not the second: MSB3073: The command "xcopy "C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.pdb" "Undefined..\UdpLocationService\bin\Plugins\" /d /y" exited with code 4. in Microsoft.Common.targets(3397, 13)Borstal
I should also add that there is no AfterBuild or exec in the csproj file. This is what it looks like: <PropertyGroup> <PostBuildEvent>xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y</PostBuildEvent> <PostBuildEvent>xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y</PostBuildEvent> </PropertyGroup>Borstal
What version of Visual Studio are you using?Depilate

© 2022 - 2024 — McMap. All rights reserved.