Search code examples
.netentity-frameworkazure-pipelinesnuget

Nuget Pack command not respecting -Exclude flag on Azure Pipeline


I'm trying to bundle, and publish, a private nuget package via Azure Pipleine but the bundled package is including some compiled EF files that causing issues.

The output below is the logs from the Azure Pipeline doing to build. The project in question has an EF edmx file and it's corresponding .vb and .Context.vb files.

- ROOT
  - DataLayer
    - EntityFramework
      - Common_Model.context.vb
      - Common_Model.edmx
      - Common_Model.vb

With the existing nuget package (from the build process below) when added to a project, it will add folders for data layer, ef and some *.tt files:

- ROOT
  - DataLayer
    - EntityFramework
      - Common_Model.context.tt
      - Common_Model.tt

This causes build problems for whatever project is referencing the nuget package. So, I'm trying to exclude those files in the nuget pack command using the command but it's not working...

> nuget.exe pack Company_PR_WS\Company_PR.vbproj -version 1.0.26 -Verbosity detailed -Exclude *.tt -OutputDirectory D:\a\8\a -Properties Configuration=release -NonInteractive
Starting: NuGet custom pack
==============================================================================
Task         : NuGet
Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version      : 2.236.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/nuget
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Detected NuGet version 6.9.1.3 / 6.9.1+guid.guid2
C:\hostedtoolcache\windows\NuGet\6.9.1\x64\nuget.exe pack Company_PR_WS\Company_PR.vbproj -version 1.0.26 -Verbosity detailed -Exclude *.tt -OutputDirectory D:\a\8\a -Properties Configuration=release -NonInteractive
NuGet Version: 6.9.1.3
Attempting to build package from 'Company_PR.vbproj'.
MSBuild auto-detection: using msbuild version '17.9.5.7608' from 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from 'D:\a\8\s\Company_PR_WS\bin\Debug'.
Add file 'D:\a\8\s\Company_PR_WS\bin\Debug\Company_WS.dll' to package as 'lib\net481\Company_WS.dll'
WARNING: NU5116: 'DataLayer\EntityFramework\Common_Model.Context.cs' was included in the project but doesn't exist. Skipping...
Add file 'D:\a\8\s\Company_PR_WS\DataLayer\EntityFramework\Common_Model.Context.tt' to package as 'content\DataLayer\EntityFramework\Common_Model.Context.tt'
WARNING: NU5116: 'DataLayer\EntityFramework\Common_Model.cs' was included in the project but doesn't exist. Skipping...
Add file 'D:\a\8\s\Company_PR_WS\DataLayer\EntityFramework\Common_Model.tt' to package as 'content\DataLayer\EntityFramework\Common_Model.tt'
Found packages.config. Using packages listed as dependencies
WARNING: NU5115: Description was not specified. Using 'Description'.

Id: Company_WS
Version: 1.0.26
Authors: Company Inc.
Description: Description
Dependencies: EntityFramework [6.2.0, ), Microsoft.Bcl.AsyncInterfaces [5.0.0, ), Newtonsoft.Json [13.0.1, ), System.Numerics.Vectors [4.5.0, ), System.Runtime.CompilerServices.Unsafe [5.0.0, ), System.Text.Encodings.Web [5.0.1, ), System.ValueTuple [4.5.0, )

Added file '[Content_Types].xml'.
Added file '_rels/.rels'.
Added file 'Company_WS.nuspec'.
Added file 'content/DataLayer/EntityFramework/Common_Model.Context.tt'.
Added file 'content/DataLayer/EntityFramework/Common_Model.tt'.
Added file 'lib/net481/Company_WS.dll'.
Added file 'package/services/metadata/core-properties/11617f753829432db4d2a240a398a665.psmdcp'.

The package Company_WS.1.0.26 is missing a readme. Go to https://aka.ms/nuget/authoring-best-practices/readme to learn why package readmes are important.
Successfully created package 'D:\a\8\a\Company_WS.1.0.26.nupkg'.


Solution

  • Based on your description, you need to exclude the *.tt files in the Nuget Package.

    To meet your requirement, you need to change the wildcard patterns format of the -exclude argument.

    You can change exclude argument from-Exclude *.tt to -Exclude **\*.tt.

    For example:

    steps:
    - task: NuGetCommand@2
      displayName: 'NuGet custom'
      inputs:
        command: custom
        includeReferencedProjects: true
        arguments: 'pack Company_PR_WS\Company_PR.vbproj -version 1.0.26 -Verbosity detailed -Exclude **\*.tt -OutputDirectory $(Build.ArtifactStagingDirectory) -Properties Configuration=release -NonInteractive'