SolutionDir 在构建后 xcopy 事件中设置为*未定义*

问题描述 投票:0回答:4

我有一个项目,它有一个构建后事件,可以将 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)

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

msbuild xcopy
4个回答
31
投票

我刚刚在 TeamCity 中遇到了同样的问题。

这里的问题是构建文件中的 $(SolutionDir) 属性。您尚未在对 MsBuild 的调用中定义它(这就是您在输出中看到单词 undefined 的原因)。

使用属性集调用 msbuild,如下所示:

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

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


8
投票

我通过添加以下内容修复了 Microsoft.SqlServer.Compact nuget 包(添加了类似的构建后脚本)的问题:

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

就在

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


4
投票

请按照以下步骤操作:

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

0
投票

我遇到了同样的问题,Philippe Mar 提供的解决方案解决了这个问题。谢谢菲利普·马尔。

© www.soinside.com 2019 - 2024. All rights reserved.