2
votes

In my Azure DevOps Build pipeline, I have added a NuGet task of pack command type (version 2.*).

I am trying to pass the -Exclude ***.tt argument so that it excludes these files when referenced from another projects. However, in the generated NuGet package, those .tt files are appearing in the Content folder.

The command written in the log of the host is:

nuget.exe pack PROJECTNAME.csproj -NonInteractive -OutputDirectory SOME_OUTPUTPATH -Properties "Configuration=release;\"-Exclude ***.tt\"" -Verbosity Detailed

As you see, exclude is not part of the properties but should be as a separate -Exclude argument.

Any idea how may I achieve this? Many thanks!

Added a screenshot and YAML:

enter image description here

steps:
- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: pack
    packagesToPack: ProjectName.csproj
    buildProperties: '-Exclude ***.tt'
3
Can you share your nuget task? (yaml or screenshot)Shayki Abramczyk
Edited the original postnaregkar

3 Answers

3
votes

When you use -Exclude with nuget pack .csproj you need to give the full path the excluded file. but there is another issue here, Azure DevOps append the -Exclude to the -Properties and it is ignore the exlucding so we need to add the -Exclude in another way, how? in NuGet custom command:

- task: NuGetCommand@2
  inputs:
    command: custom
    arguments: 'pack "$(Build.SourcesDirectory)\Path\To\.csproj" -Exclude "$(Build.SourcesDirectory)\Path\to\*.tt"'

Here a log from the regular -Exclude as you tried, you can see that the nuget pack my .exe file:

enter image description here

And here a log after I make the custom command, there is no .exe:

enter image description here

My task is:

- task: NuGetCommand@2
  inputs:
    command: custom
    arguments: 'pack "$(Build.SourcesDirectory)\TestVars\TestVars\TestVars.csproj" -Exclude "$(Build.SourcesDirectory)\TestVars\TestVars\bin\Debug\*.exe"'
2
votes

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":

enter image description here

Then we could to know, the .cs is excluded in the package.

Hope this helps.

0
votes

It solved for me in Visual Studio 2015:

<ItemGroup>
    <None Include="**.tt">
        <Pack>False</Pack>
        <Generator>TextTemplatingFileGenerator</Generator>
        <LastGenOutput>Test.txt</LastGenOutput>
    </None>
    ...
</ItemGroup>