0
votes

I have an VS solution file (.sln) which consists .net standard libraries and test projects. Now the project has an Integration test project that is targeted against .net Framework 4.7.2.

My current build pipeline does the following dotnet build dotnet pack dotnet push

With the dotnet pack, I am trying to excldude the project Integration.Tests.csproj.

My current folder structure looks like the following

CompanyName.Service\CompanyName.Service.csproj
CompanyName.Data\CompanyName.Data.csproj
Integration.Tests\Integration.Tests.csproj

According to the helper tooltip in the path to include/exclude we can do it like the following

**/*.csproj;-:**/*.Tests.csproj

enter image description here

However the dotnet pack task simply is not ignoring the Integration.Tests.csproj. It tries to pack it and it fails. I'm not sure what I am doing wrong or if this is an issue with the task. I haven't been able to locate any known issues on this so far.

Note: Prior to having that project in my solution, the pipeline was working fine with the projects being packed and published to nuget.

2
In your screenshot you use ! and not -:Shayki Abramczyk
Sorry it was a bad screenshot. But the actual data is as I mentioned in the comment. I was trying it with exclamation when I took that shotSrini
What is version of your dotnet pack task you are using? Is 2.*?Leo Liu-MSFT
@Srini So try with !, I think -: it's old syntax.Shayki Abramczyk

2 Answers

1
votes

If you are using the version (2.x) of the dotnet task in Azure Devops, you should use ! instead of -:.

Because the exclude pattern has changed. That these patterns were updated in version 2 of the NuGet task; if you have a pattern that contains -:, use ! instead:

Pack NuGet packages

enter image description here

As test, it works fine on my side.

My folder setup:

enter image description here

Note: If you still have issue with that task, please check the if the error comes from build not packing when you running that task. Or you can select the option Do not build:

enter image description here

But you should build the project before you packing it.

0
votes

Apart of including only the necessary files (one), you can modify the pipeline to build only the needed resources (two). The details:

One) This is the main answer to your question: the package operation will include the dependencies, so you only need to package the main project. In the image below, you can see in yellow the path and filename of the main project of the package (instead of guessing, click the button pointed by the read arrow to browse for it). As explained, the dependencies will be automatically included. You don't need to include them explicitly. This also includes the required Nuget packages, which are included as dependent packages.

nuget pack properties

Two) By default, the build configuration is defined in the $(BuildConfiguration) variable of the pipeline and it's usually Release (above, in green). If you want to save compute efforts and time in your pipeline, you can create a new Solution configuration inside Visual Studio. Below you can see a solution configuration already created, with the name Package. To create it:

  • in configuration manager, click <New...>(in green below)
  • specify a name for the configuration (Package)
  • choose the configuration of the projects (Release or Debug) or create a new one. Creating a new one is only useful if your project needs to do something special for packaging, for example, if you have configuration transforms. In the example, the main project has the Package configuration.
  • in the configuration specify the projects that need to be built. Include the main project and their dependencies. In this example the main project doesn't depend on others, so it's the only one checked in the Build column. You usually exclude the test projects, proof of concepts, and this kind of projects.
  • the last step is in the pipeline itself: specify the solution configuration (Package) directly in the green text box of the first snapshot, or as the value of that variable, in the Variables tab of the pipeline enter image description here

If you do so, only the needed projects will be compiled, and all the dependencies will be included in the package.