Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Exclude a T4 Template from a NuGet Package

Tags:

nuget

t4

I'm creating a NuGet package the provides a client for my WebAPI project by reflecting over the ApiControllers and creating classes for each one with methods that correspond to the actions defined on the controller. Unfortunately the .tt file is being included in the content folder when I run nuget.exe pack Client.csproj. I've tried creating a .nuspec file with a <files> directive, but I can't seem to exclude the file by itself. Does anyone know how to force the package to exclude the T4 template?

The project structure is roughly:

Website/
    Controllers/
        UserController.cs
        ...
Client/
    Client.tt
    Client.cs
        namespace Client
            class UserService
            ...

And I'd like a NuGet package like:

lib/
    net45/
        Client.dll
            namespace Client
                class UserService

But I'm getting something like this:

content/
    Client.tt
lib/
    net45/
        Client.dll
            namespace Client
                class UserService
                ...
like image 242
Kyle Sletten Avatar asked Nov 11 '15 18:11

Kyle Sletten


3 Answers

NuGet.exe Pack Client.csproj -Exclude **/*.tt
like image 184
Patrick Michalina Avatar answered Nov 20 '22 06:11

Patrick Michalina


In my case the problem was inside csproj file, I had to fix

<Content Include="SomeFile.txt" />

to

<None Include="SomeFile.txt" />
like image 3
baur Avatar answered Nov 20 '22 06:11

baur


Turns out the easy solution is to use the -Exclude option when creating the package via the command line.

NuGet.exe Pack Client.csproj -Exclude *.tt

The new package will look exactly as specified in the question.

like image 2
Kyle Sletten Avatar answered Nov 20 '22 07:11

Kyle Sletten