简体   繁体   English

将文本模板(* .tt)包含在.NET Standard NuGet包中

[英]Including Text Template (*.tt) into the .NET Standard NuGet Package

I publish a .NET Standard class library as a package on MyGet feed by selecting “Generate NuGet Package on Build” in project settings and using MyGet building service. 我通过在项目设置中选择“在构建时生成NuGet包”并使用MyGet构建服务,在MyGet源上将.NET标准类库作为包发布。 My Cds.IoC.csprj looks like this: 我的Cds.IoC.csprj看起来像这样:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RootNamespace>Cds.IoC</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Authors>...</Authors>
    <Company>...</Company>
    <Product>...</Product>
    <Description>...</Description>
    <Copyright>© 2018</Copyright>
    <PackageTags>...</PackageTags>
    <PackageReleaseNotes>...</PackageReleaseNotes>
    <AssemblyVersion>0.0.0.1</AssemblyVersion>
    <FileVersion>0.0.0.1</FileVersion>
    <Version>1.0.1-alpha</Version>
  </PropertyGroup>
</Project>

How can I add a Text Template Some.tt file to the package, so it will show up in the referencing project? 如何向包中添加文本模板Some.tt文件,以便它将显示在引用项目中? I would not like it to generate output on package build; 我不希望它在包构建上生成输出; just looking for a way to automatically add the TT file to the referencing project. 只是想找到一种方法来自动将TT文件添加到引用项目中。

How can I add a Text Template Some.tt file to the package, so it will show up in the referencing project? 如何向包中添加文本模板Some.tt文件,以便它将显示在引用项目中?

You can use the property <Pack>true</Pack> to add the Text Template Some.tt file to the package: 您可以使用属性<Pack>true</Pack>将Text Template Some.tt文件添加到包中:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RootNamespace>Cds.IoC</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Authors>...</Authors>
    <Company>...</Company>
    <Product>...</Product>
    <Description>...</Description>
    <Copyright>© 2018</Copyright>
    <PackageTags>...</PackageTags>
    <PackageReleaseNotes>...</PackageReleaseNotes>
    <AssemblyVersion>0.0.0.1</AssemblyVersion>
    <FileVersion>0.0.0.1</FileVersion>
    <Version>1.0.1-alpha</Version>
  </PropertyGroup>
  <ItemGroup>
    <None Update="some.tt">
      <Generator>TextTemplatingFileGenerator</Generator>
      <LastGenOutput>some.txt</LastGenOutput>    
    </None>
    <None Update="some.txt">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>some.tt</DependentUpon>
      <Pack>true</Pack>
    </None>
  </ItemGroup>
</Project>

When you build the project, the generated source file some.tt will added to the nuget package, then you add this nuget package to the project, this file will added to the project. 在构建项目时,生成的源文件some.tt将添加到nuget包中,然后将此nuget包添加到项目中,此文件将添加到项目中。

Check the document NuGet pack and restore as MSBuild targets for some more details. 检查文档NuGet包并恢复为MSBuild目标以获取更多详细信息。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .Net Standard 2.0 生成 NuGet package 包括同一解决方案中的项目和 NuGet 包 - .Net Standard 2.0 Generate NuGet package including projects in the same solution and NuGet packages 自定义.NET Standard Nuget软件包无法正确安装 - Custom .NET Standard Nuget package not installing correctly 使用NET Standard 1.X的Nuget包 - Nuget package with NET Standard 1.X 适用于CRM REST的.NET Standard 2.0 Nuget软件包 - .NET Standard 2.0 Nuget package for CRM REST 如何将 .Net Standard Nuget 包添加到 .Net 4.5 Framework 项目中? - How to add .Net Standard Nuget package into .Net 4.5 Framework Project? 在.NET Core Web API中安装自定义.NET Standard NuGet软件包 - Install custom .NET Standard NuGet Package in .NET Core Web API 无法为 NET Standard 加载 NuGet 包的文件或程序集异常 NET 5/6 - could not load file or assembly exception NET 5/6 of NuGet package for NET Standard 如何在VS 2017中创建具有最小依赖性的.NET Standard NuGet包? - How to create .NET Standard NuGet package with minimal dependencies in VS 2017? 如何将nuget包.Net Standard嵌入到项目C#中? - How to embed nuget package .Net Standard into a project C#? 从.Net Standard项目和本机dll创建nuget包 - Create a nuget package from .Net Standard project and Native dlls
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM