Exclude/Remove .csproj 通过 MSBuild 参数

Exclude/Remove .csproj through MSBuild argument

我需要在团队构建编译期间从 .sln 文件中排除 abc.Test.csproj

我试过使用 /ignoreprojectextensions=.Test.csproj,但对我的目的不起作用。请帮我完成这个。

您将创建一个新配置(Debug 和 Release 是默认配置),并且在这个新配置中,您不会构建指定的 .csproj。

然后您将构建到该配置。

参见:

Does Msbuild recognise any build configurations other than DEBUG|RELEASE

追加

如果不进行 new/custom 配置,这是我能推断出的唯一解决方案。

将下面 xml 左右的代码放在一个名为 "MyBuild.proj" 的文件中,保存它,然后调用

msbuild.exe MyBuild.proj

..

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">

    <PropertyGroup>
        <WorkingDirectory>.</WorkingDirectory>
    </PropertyGroup>

    <Target Name="AllTargetsWrapped">
        <CallTarget Targets="ShowReservedProperties" />
        <CallTarget Targets="BuildOtherProjects" />
    </Target>

    <Target Name="BuildOtherProjects">

        <ItemGroup>
            <ProjectReferencesExcludes Include="$(WorkingDirectory)\UnitTests.csproj" />
            <ProjectReferencesExcludes Include="$(WorkingDirectory)\SomeOtherProject.csproj" />
        </ItemGroup>

        <ItemGroup>
            <ProjectReferences Include="$(WorkingDirectory)\**\*.*proj" Exclude="@(ProjectReferencesExcludes)" />
        </ItemGroup>

        <Message Text="List of projs to be built:"/>
        <Message Text="@(ProjectReferences->'&quot;%(fullpath)&quot;' , '%0D%0A')"/>
        <Message Text="   "/>
        <Message Text="   "/>

        <MSBuild
            Projects="@(ProjectReferences)"
            Targets="Build">
            <Output
                TaskParameter="TargetOutputs"
                ItemName="AssembliesBuiltByChildProjects" />
        </MSBuild>

    <Message Text="   "/>
    <Message Text="   "/>           
    <Message Text="List of AssembliesBuiltByChildProjects:"/>
    <Message Text="@(AssembliesBuiltByChildProjects->'&quot;%(fullpath)&quot;' , '%0D%0A')"/>
    <Message Text="   "/>
    <Message Text="   "/>   


    </Target>

    <Target Name="ShowReservedProperties">  

        <Message Text="MSBuild: $(MSBuild)"/>
        <Message Text="MSBuildBinPath: $(MSBuildBinPath)"/>
        <Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)"/>
        <Message Text="MSBuildExtensionsPath32: $(MSBuildExtensionsPath32)"/>
        <Message Text="MSBuildExtensionsPath64: $(MSBuildExtensionsPath64)"/>
        <Message Text="MSBuildLastTaskResult: $(MSBuildLastTaskResult)"/>
        <Message Text="MSBuildNodeCount: $(MSBuildNodeCount)"/>
        <Message Text="MSBuildOverrideTasksPath: $(MSBuildOverrideTasksPath)"/>
        <Message Text="MSBuildProgramFiles32: $(MSBuildProgramFiles32)"/>
        <Message Text="MSBuildProjectDefaultTargets: $(MSBuildProjectDefaultTargets)"/>
        <Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/>
        <Message Text="MSBuildProjectDirectoryNoRoot: $(MSBuildProjectDirectoryNoRoot)"/>
        <Message Text="MSBuildProjectExtension: $(MSBuildProjectExtension)"/>
        <Message Text="MSBuildProjectFile: $(MSBuildProjectFile)"/>
        <Message Text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)"/>
        <Message Text="MSBuildProjectName: $(MSBuildProjectName)"/>
        <Message Text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)"/>
        <Message Text="MSBuildThisFile: $(MSBuildThisFile)"/>
        <Message Text="MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)"/>
        <Message Text="MSBuildThisFileDirectoryNoRoot: $(MSBuildThisFileDirectoryNoRoot)"/>
        <Message Text="MSBuildThisFileExtension: $(MSBuildThisFileExtension)"/>
        <Message Text="MSBuildThisFileFullPath: $(MSBuildThisFileFullPath)"/>
        <Message Text="MSBuildThisFileName: $(MSBuildThisFileName)"/>
        <Message Text="MSBuildToolsPath: $(MSBuildToolsPath)"/>
        <Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)"/>       

    </Target>   





</Project>

注意,如果你将一个 csproj 放在排除列表中,但在其上放置另一个 csproj references/depends,它将被构建(无论你 "exclude").