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.
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
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;
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.