1
votes

I have a solution with .NET Core 3.1 projects and those include test projects (xUnit). And I created a pipeline in the Azure DevOps which builds Nuget packages. And for some reason it creates packages for test projects too, even when they have

<IsPackable>false</IsPackable>

How can I exclude project from being packaged with Nuget?

The pipeline uses Windows 2019 agent, .NET Core 3.1, latest Nuget, NuGet pack and NuGet push tasks.

3

3 Answers

2
votes

If you add the NuGet Task through the Gui, it provides the solution to your problem:

**\*.csproj;!**\*.Tests.csproj

Your Nuget command should look something like this:

- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: 'pack'
    packagesToPack: '**\*.csproj;!**\*.Tests.csproj'
    versioningScheme: #yourversioningscheme

screenshot from AzDO

If the solution you are building has projects you don't wish to pack then you would have to manually reference the projects you wish to package.

**\Foo.csproj;

1
votes

As @jKlaus suggested, instead of using a single pack task with **/*.csproj pattern, you should use multiple pack tasks - 1 per project. For example, for a particular project, you will have this step:

steps:
- task: NuGetCommand@2
  displayName: 'Pack ProjectName'
  inputs:
    command: pack
    packagesToPack: ProjectName/ProjectName.csproj
    versioningScheme: byPrereleaseNumber

And there will be others for different projects.

0
votes

You can specifically target the project to package with every step I've ever used. I think IsPackable is only respected by dotnet, not nuget.