Passing NuGet 'Pack' arguments in Azure DevOps Build Pipeline
You could not use the argument -Exclude
in this way. That because this argument is used for .nuspec
not .csproj
, -Exclude
is not the Property in the project file, so we could not use it with .csproj
.
When you check the nuget document nuget pack command (NuGet CLI), you can see the following example:
nuget pack Package.nuspec -exclude "*.exe" -exclude "*.bat"
If you want to exclude .tt
files with project file .csproj
, you have to go to your project file to excluded this type of file, like:
<ItemGroup>
<None Update="**.tt">
<Pack>False</Pack>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Test.txt</LastGenOutput>
</None>
...
</ItemGroup>
If you do not want to modify the source file, you can create the .nuspec
file, then pack the .nuspec
file with argument -Exclude
.
For example, I create following .nuspec
:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MyTestCore</id>
<version>6.0.0</version>
<authors>TestContentFile</authors>
<owners>TestContentFile</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<contentFiles>
<files include="any/any/Data.xml" buildAction="content" flatten="true" copyToOutput="true"/>
<files include="any/any/Test.cs" buildAction="content" flatten="true" copyToOutput="true"/>
</contentFiles>
</metadata>
<files>
<file src="contentFiles/any/any/Data.xml" target="contentFiles/any/any/Data.xml" />
<file src="contentFiles/any/any/Test.cs" target="contentFiles/any/any/Test.cs" />
</files>
</package>
If I pack this .nuspec file with argument -Exclude "**\*.cs"
:
Then we could to know, the .cs
is excluded in the package.
Hope this helps.