首页 > 解决方案 > MSBUILD 排除 cs 文件

问题描述

我有一个带有以下类/接口的类库(TestClassLib)。

IA.cs

A.cs(实现 IA)

IB.cs

B.cs(实现 IB)

A 和 B 没有依赖关系。

在 TestClasslib.csproj 中,我有以下 XML


  <PropertyGroup>
    <Builtdir>built</Builtdir>
    <AssemblyName>Dabba</AssemblyName>
    <OutputPath>Bin\</OutputPath>
    <Configurations>Debug;Release;Test</Configurations>
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>


  <ItemGroup>
    <CSFile Include="*.cs;" Exclude="B.cs" />
  </ItemGroup>

  <Target Name="Compile">
    <Csc Sources="@(CSFile)" OutputAssembly="$(AssemblyName).dll" TargetType="dll" />
  </Target>
</Project>

只想在创建 dll 时排除 B.cs。是否可以排除少数不依赖其他类的类?

标签: c#.netmsbuild

解决方案


如果要在构建过程中排除某些类,请在.csproj. 那么生成dll的就没有关系了B.cs

<ItemGroup>
  <Compile Remove="B.cs" />
</ItemGroup>

推荐阅读