MSBuild - csproj - 使用组合从构建中排除文件夹

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

为了允许在 Visual Studio 和 Linux DevContainer 中并行构建我们的项目,我更改了项目的构建配置,如下所示:

目录.Build.props

<Project>
  <PropertyGroup Condition=" '$(OS.StartsWith(`Windows`))' == 'true' ">
    <MSBUildProjectExtensionsPath>$(MSBuildThisFileDirectory)$(MSBuildProjectName)\obj-windows\</MSBUildProjectExtensionsPath>
    <BaseOutputPath>$(MSBuildThisFileDirectory)$(MSBuildProjectName)\bin-windows\</BaseOutputPath>
    <NoWarn>MSB3539</NoWarn>    <!-- Temporary Suppress warning about BaseIntermediateOutputPath -->
  </PropertyGroup>
  <PropertyGroup Condition=" '$(OS.StartsWith(`Windows`))' != 'true' ">
    <MSBUildProjectExtensionsPath>$(MSBuildThisFileDirectory)$(MSBuildProjectName)/obj-linux/</MSBUildProjectExtensionsPath>
    <BaseOutputPath>$(MSBuildThisFileDirectory)$(MSBuildProjectName)/bin-linux/</BaseOutputPath>
    <NoWarn>MSB3539</NoWarn>    <!-- Temporary Suppress warning about BaseIntermediateOutputPath -->
  </PropertyGroup>
</Project>

这会将

bin
文件分别重定向到
bin-windows
bin-linux
obj
文件夹也是如此。

问题在于,这在 .NET 编译中包含了这些文件夹

enter image description here

如果您在 Windows/Linux 上进行交替构建,这会导致递归树

enter image description here

我可以通过将以下代码片段添加到我的 csproj 文件中来解决此问题

<ItemGroup>
    <Compile Remove="bin-linux\**" />
    <Compile Remove="bin-windows\**" />
    <Compile Remove="obj-linux\**" />
    <Compile Remove="obj-windows\**" />
    <Content Remove="bin-linux\**" />
    <Content Remove="bin-windows\**" />
    <Content Remove="obj-linux\**" />
    <Content Remove="obj-windows\**" />
    <EmbeddedResource Remove="bin-linux\**" />
    <EmbeddedResource Remove="bin-windows\**" />
    <EmbeddedResource Remove="obj-linux\**" />
    <EmbeddedResource Remove="obj-windows\**" />
    <None Remove="bin-linux\**" />
    <None Remove="bin-windows\**" />
    <None Remove="obj-linux\**" />
    <None Remove="obj-windows\**" />
</ItemGroup>

但是我想这样写

<ItemGroup>
    <Compile Remove="**\(bin|obj)-(linux|windows)\**" />
    <Content Remove="**\(bin|obj)-(linux|windows)\**" />
    <EmbeddedResource Remove="**\(bin|obj)-(linux|windows)\**" />
    <None Remove="**\(bin|obj)-(linux|windows)\**" />
</ItemGroup>

但这似乎不起作用。有办法做到这一点吗?

我创建了一个存储库在这里

.net msbuild csproj
1个回答
0
投票

不支持正则表达式来选择文件,仅支持通配模式。

如果您的项目没有任何其他带有

bin-
obj- 
前缀的文件夹,那么您可以考虑排除以下任何以
bin-
obj-
开头的文件夹。

<ItemGroup>
  <Compile Remove="bin-*\**;obj-*\**" />
  <Content Remove="bin-*\**;obj-*\**" />
  <EmbeddedResource Remove="bin-*\**;obj-*\**" />
  <None Remove="bin-*\**;obj-*\**" />
</ItemGroup>
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.