How to Exclude a T4 Template from a NuGet Package
Asked Answered
F

5

5

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
                ...
Floyfloyd answered 11/11, 2015 at 18:38 Comment(0)
F
2

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.

Floyfloyd answered 17/11, 2015 at 18:31 Comment(2)
A nice gotcha - it doesn't exclude any .tt files in subdirectories, you have to also exclude those in your list.Malvina
To exclude everything, just do -Exclude */.ttMalvina
L
8
NuGet.exe Pack Client.csproj -Exclude **/*.tt
Latency answered 11/11, 2016 at 4:15 Comment(0)
K
5

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

<Content Include="SomeFile.txt" />

to

<None Include="SomeFile.txt" />
Kirovabad answered 22/5, 2019 at 13:49 Comment(0)
F
2

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.

Floyfloyd answered 17/11, 2015 at 18:31 Comment(2)
A nice gotcha - it doesn't exclude any .tt files in subdirectories, you have to also exclude those in your list.Malvina
To exclude everything, just do -Exclude */.ttMalvina
V
1

To build on @Baur's answer you can set this:

<None Include="SomeFile.tt" />

From the IDE, by right clicking the files and going to properties.

Click the BuildAction Property Set it to None

Vile answered 20/8, 2020 at 16:9 Comment(0)
C
0

If you are using Azure DevOps, I tried for a long time either trying using a custom nuget pack command with the -exclude, which did not work, or tried adding a .nuspec file and excluding the content from there. However, nothing worked.

How I fixed it in our project is clicking on each .tt file and setting the "Build Action" from "Content" to "None". It didn't seem to have an affect on the project in any way.

Maybe someone has a better solution, but I struggled with it for 1-2 days until I decided to screw it and just change the build action.

Cheddar answered 7/2, 2019 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.