ProjectReference is an item, you can add the Item to be conditionally excluded inside a conditioned ItemGroup:
<PropertyGroup> <ExcludeReference Condition="'$(ExcludeReference)'==''">false</ExcludeReference> </PropertyGroup> <ItemGroup Condition="'$(ExcludeReference)'=='true'"> <ProjectReference Include="..\B\B.csproj"> <Project>{7B68745C-382E-4272-897D-123A0AD80391}</Project> <Name>B</Name> </ProjectReference> </ItemGroup>
From the command line you can pass:
MsBuild SomeProject.proj /p:ExcludeReference=true
UPDATE:
You can have your optional reference in a separate project and import it:
ConditionalReferences.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <ProjectReference Include="..\B\B.csproj"> <Project>{7B68745C-382E-4272-897D-123A0AD80391}</Project> <Name>B</Name> </ProjectReference> </ItemGroup> </Project>
And in your .csproj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <ExcludeReference Condition="'$(ExcludeReference)'==''">false</ExcludeReference> </PropertyGroup> <Import Project="ConditionalReferences.proj" Condition="'$(ExcludeReference)'=='false'"/> </Project>