在后期构建的复制事件中,SolutionDir设置为*Undefined*

13

我有一个项目,其中包含一个后期构建事件,将DLL文件复制到特定目录:

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

然而,我已经设置了CruiseControl.NET作为构建服务器,但由于以下xcopy后置事件,MSBuild在构建该项目时失败:

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)

有什么建议可以解决这个问题吗?

3个回答

31

我也在TeamCity上遇到了同样的问题。

这里的问题是你的构建文件中 $(SolutionDir) 属性没有被定义。因此,你在输出中看到了单词“undefined”。

通过设置该属性来调用msbuild,像这样:

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

“解决方案目录”是包含您的解决方案文件的目录。请注意末尾的斜杠,您需要它来确保路径正确形成。


1
或者您可以将尾随斜杠包含在双引号内 - 只需记得用另一个反斜杠进行转义。因此,在我的情况下,调用将是msbuild myproject.csproj /property:SolutionDir="%teamcity.build.checkoutdir%\ " - David Keaveny

8
我解决了与Microsoft.SqlServer.Compact nuget包(它添加了类似的后置构建脚本)相关的问题,方法是添加以下内容:
<SolutionDir Condition="'$(SolutionDir)'=='' or '$(SolutionDir)'=='*Undefined*'">..\</SolutionDir>

<PostBuildEvent>的正上方。您需要调整相对路径以匹配您的项目布局。


2
这个错误可能会在构建项目而不是解决方案时发生。当这种情况发生时,$(SolutionDir)实际上是未定义的,上面的解决方案可以绕过这个限制。 - Philippe

4

按照以下步骤操作:

  • 卸载您的项目文件(例如*.csproj)
  • 打开您的项目文件进行编辑
  • 查找AfterBuild目标
  • 将两个XCopy调用分别分离为两个不同的Exec任务
  • 保存更改并重新加载项目文件

谢谢,这修复了第一个错误,但没有修复第二个:MSB3073:命令“xcopy“C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.pdb”“Undefined..\UdpLocationService\bin\Plugins\” /d /y”的退出代码为4。在Microsoft.Common.targets(3397,13)中。 - Justin
我还应该补充一点,csproj文件中没有AfterBuild或exec。它看起来像这样: <PropertyGroup> <PostBuildEvent>xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)..\UdpLocationService\bin\Plugins&quot; /d /y</PostBuildEvent> <PostBuildEvent>xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\UdpLocationService\bin\Plugins&quot; /d /y</PostBuildEvent> </PropertyGroup> - Justin
你使用的是哪个版本的Visual Studio? - Jim Lamb

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接