How to Exclude a T4 Template from a NuGet Package

守給你的承諾、 提交于 2019-12-07 07:30:35

问题


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
                ...

回答1:


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



回答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.




回答3:


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.




回答4:


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

<Content Include="SomeFile.txt" />

to

<None Include="SomeFile.txt" />


来源:https://stackoverflow.com/questions/33657526/how-to-exclude-a-t4-template-from-a-nuget-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!