如何从 NuGet 包中排除 T4 模板 [英] How to Exclude a T4 Template from a NuGet Package

查看:74
本文介绍了如何从 NuGet 包中排除 T4 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 NuGet 包,它通过反射 ApiController 并使用与控制器上定义的操作相对应的方法为每个类创建类,从而为我的 WebAPI 项目提供客户端.不幸的是,当我运行 nuget.exe pack Client.csproj 时,.tt 文件包含在内容文件夹中.我已经尝试使用 <files> 指令创建一个 .nuspec 文件,但我似乎无法单独排除该文件.有谁知道如何强制包排除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?

项目结构大致如下:

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

我想要一个 NuGet 包,例如:

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

推荐答案

事实证明,简单的解决方案是在通过命令行创建包时使用 -Exclude 选项.

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.

这篇关于如何从 NuGet 包中排除 T4 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆