【问题标题】:Build .net core project by postbuild event in visual studio 2017在 Visual Studio 2017 中通过 postbuild 事件构建 .net 核心项目
【发布时间】:2017-04-26 08:51:06
【问题描述】:

我有项目A,它依赖于项目B,但没有从BA 的引用。我想在项目Bbin folder 中构建和复制程序集到项目Abin folder。如何使用构建后事件和dotnet msbuild 来做到这一点。

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

Build another project by prebuild event without adding reference

【问题讨论】:

  • 这个问题呢?请告诉我有关此问题的最新信息吗?
  • @Leo-MSFT 您的解决方案完美运行,谢谢。

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


【解决方案1】:

这对我有用。来自: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>

【讨论】:

  • 很好的答案,但有一个错字“如果不存在 $(OutDir)..\..\..\.\build” 缺少“。”就在构建之前。应该是“如果不存在 $(OutDir)..\..\..\..\build”
【解决方案2】:

如何使用构建后事件和 dotnet msbuild 来做到这一点

您可以在项目 A 的 post build 事件中添加 Build taskcopy task 来实现您的要求:

"$(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

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2017-08-18
    • 2018-05-19
    • 2018-06-02
    • 2018-11-11
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    相关资源
    最近更新 更多