通过Visual Studio 2017中的postbuild活动构建.net核心项目

时间:2017-04-26 08:51:07

标签: visual-studio msbuild .net-core visual-studio-2017 post-build-event

我的项目A依赖于项目B,但没有BA的引用。我希望在项目bin folder的{​​{1}}到项目B的{​​{1}}内构建和复制程序集。如何使用帖子构建事件和bin folder来完成此操作。

我找到了这个链接,但它适用于VS 2015及以下版本和MS-Build:

Build another project by prebuild event without adding reference

2 个答案:

答案 0 :(得分:6)

这对我有用。它来自:https://github.com/dotnet/sdk/issues/677

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="if not exist $(OutDir)..\..\..\.\build  mkdir $(OutDir)..\..\..\..\build" />
    <Exec Command="copy $(OutDir)$(TargetName).dll $(OutDir)..\..\..\..\build\$(TargetName).dll /Y" />
    <Exec Command="copy $(OutDir)$(TargetName).pdb $(OutDir)..\..\..\..\build\$(TargetName).pdb /Y" />
</Target>

答案 1 :(得分:3)

  

如何使用post build事件和dotnet msbuild

执行此操作

您可以在项目A的后期制作活动中添加构建任务复制任务以实现您的请求:

"$(MSBuildBinPath)\MSBuild.exe" "$(SolutionDir)ProjectB\ProjectB.csproj"
 xcopy.exe "$(SolutionDir)ProjectB\bin\Debug\netcoreapp1.1\ProjectB.dll" "$(SolutionDir)ProjectA\bin\Debug\netcoreapp1.1"

如果项目B的bin文件夹中有多个程序集,您还可以使用通配符复制程序集,例如

xcopy.exe "$(SolutionDir)ProjectB\bin\Debug\netcoreapp1.1\*.dll

希望这可以帮到你。