Afnan Ashraf
Afnan Ashraf

Reputation: 314

Excluding projects in MSBuild CLI

I'm trying to automate a .Net console application build from Jenkins using MSBuild plugin. There are a total of 36 projects present in the solution when I'm using Visual Studio 4 projects are showing unloaded and build was successful. But when I try to build it using MSBuild, MSBuild tries to load these unloaded projects and fails. I have used configuration which does not contain these projects still MSBuild tries to build it. 32 projects are written n C# and remaining are in C++. Is there any way to exclude these projects and build them.

Upvotes: 0

Views: 2909

Answers (1)

Mr Qian
Mr Qian

Reputation: 23760

Excluding projects in MSBuild CLI

I think you should write a custom build script to remove those projects based on your requirements.

For an example,

create a file called test.csproj and then add these in it:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <ItemGroup>
    <MyProjectReferences Include="**\*.*proj" />
    <MyProjectReferences Remove="xxx\xxxx.vcxproj;xxx\vxproj;test.csproj" /> //add any projects here you want to exclude 
  </ItemGroup>



  <Target Name="BuildProject">
    <MSBuild Projects="@(MyProjectReferences)" Targets="Build" />
  </Target>

 <Target Name="CleanProject">
 <MSBuild Projects="@(MyProjectReferences)" Targets="Clean" />
</Target>

</Project>

Note: You should also remove test.csproj because **\*.*proj already contains it and you should remove it to avoid getting into an endless loop.

Then, upload the test.csproj file into Jenkins and please put the file on the solution folder on Jenkins

Also remember to check the relative path in the test.csproj file again to make sure you can find all the items based on the current cloud address.

==============================

When you use MSBuild.exe to build project in Jenkins, please set MSBuild Build File to test.csproj

then set Command Line Arguments to

-t:BuildProject -p:Configuration=Debug xxxxxx

Besides, it is the same on Azure Devops, you should instead use MSBuild Task and then specify the test.csproj file to get what you want.

Upvotes: 1

Related Questions