msbuild - 根据项目名称设置 msbuild OutputPath
问题描述
我正在尝试改进 .NET 解决方案的构建服务器设置。构建是使用完成msbuild solution.sln /p:OutputPath="$pwd/build"
的,另外还有一个Directory.Solution.targets
解决 msbuild 的怪癖(来自相关问题,请参阅下面的内容)。现在我们决定将测试转移到单独的项目中,这样测试 dll 及其依赖项就不会出现在 OutputPath 中。通常这不是问题,但由于历史原因,解决方案中的每个项目都将其 OutputPath 设置为..\..\
. 这就是为什么我在调用时覆盖它的原因msbuild
。但现在我只需要为一些项目覆盖它——我不知道怎么做。
现在的项目结构如下所示。
app/
sources/
Complete.sln
Proj1/
proj1.csproj
Proj1.Test/
proj1.test.csproj
开发人员从 Visual Studio 构建解决方案会导致此结果(仅显示新文件),这很好。
app/
proj1.exe
sources/Proj1.Tests/bin/Release/
proj1.exe
proj1.tests.dll
但是构建它会msbuild Complete.sln /p:OutputPath="$pwd/build" /t:BuildAll
导致以下结果。
app/build/
proj1.exe
proj1.tests.dll
有没有办法在不更改解决方案或项目文件的情况下获得以下内容?
app/build/
proj1.exe
app/tests/
proj1.exe
proj1.tests.dll
即我想将OutputPath
for each 设置*.Tests.csproj
为/tests
,并将 for each other project 设置为/build
。
或者,有没有办法以msbuild Complete.sln
这样的方式调用它从该解决方案构建所有项目,其名称不以“测试”结尾,或者只构建那些名称?
上面提到的Directory.Solution.targets
(使用它的原因)如下所示。
<Project>
<Target Name="SetSkip">
<ItemGroup>
<ProjectReference Update="*">
<SkipNonexistentProjects>Build</SkipNonexistentProjects>
</ProjectReference>
</ItemGroup>
</Target>
<Target Name="BuildAll" DependsOnTargets="SetSkip">
<CallTarget Targets="Build"/>
</Target>
</Project>
UPDATE因为文件数量增加,为了更容易测试我创建了一个存储库。
解决方案
您可以尝试将以下内容添加到Directory.Build.targets
(我尚未对其进行测试,但应该可以):
<PropertyGroup>
<OutputPath Condition="'$(BuildOutputPath)' != ''
and !$(MSBuildProjectName.EndsWith('.Test'))">$(BuildOutputPath)</OutputPath>
<OutputPath Condition="'$(TestOutputPath)' == ''
and $(MSBuildProjectName.EndsWith('.Test'))">$(TestOutputPath)</OutputPath>
</PropertyGroup>
然后像这样调用 msbuild:
msbuild Complete.sln /p:TestOutputPath="$pwd\tests" /p:BuildOutputPath="$pwd\build"
还有其他选项,例如将所需的build
或tests
路径直接放在属性中。
推荐阅读
- angular7 - 如何使用 ngx-leaflet-draw 为 ngx-leaflet 创建自定义绘制按钮
- visual-studio-code - 禁用多光标功能
- wordpress - POST 方法时拒绝 wordpress wp-admin/post.php 的访问
- vuetify.js - Vuetify v-text-field:如何根据规则自动设置成功状态
- spring - 如何在 Spring Reactor Web 应用程序中执行一系列操作并确保一个操作在下一个操作之前完成?
- r - 从带有“lda2”、“qda”、“lda”的 Caret 训练模型中检索变量重要性
- signal-processing - 如何消除无线电信号的瞬态
- c# - 绑定到显式接口索引器实现
- ruby - RVM 安装 Ruby 2.1.2:配置:错误:无法计算 sizeof (long long)
- sql - 匹配没有国民身份证的人