SolutionDir在构建后的xcopy事件中设置为*Undefined*

Jus*_*tin 10 msbuild xcopy

我有一个项目,有一个后期构建事件,可以将DLL复制到某个目录:

xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y
xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y
Run Code Online (Sandbox Code Playgroud)

但是,我将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)
Run Code Online (Sandbox Code Playgroud)

有任何建议来解决这个问题吗?

and*_*axo 25

我刚刚遇到与TeamCity相同的问题.

这里的问题是构建文件中的$(SolutionDir)属性.你没有在调用MsBuild时定义它(这就是为什么你在输出中看到单词undefined的原因).

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

msbuild myproject.csproj /property:SolutionDir="solution directory"\
Run Code Online (Sandbox Code Playgroud)

"解决方案目录"是包含解决方案文件的目录.请注意尾部斜杠,您需要确保正确形成路径.


Tom*_*eld 7

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

<SolutionDir Condition="'$(SolutionDir)'=='' or '$(SolutionDir)'=='*Undefined*'">..\</SolutionDir>
Run Code Online (Sandbox Code Playgroud)

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

  • 构建项目而不是解决方案时可能会发生此错误.当发生这种情况时,$(SolutionDir)实际上是*undefined*并且上面的解决方案绕过了限制. (2认同)

Jim*_*amb 4

按着这些次序:

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