3

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. My Cds.IoC.csprj looks like this:

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

Dmitry Nogin
  • 3,670
  • 1
  • 19
  • 35
  • Possible duplicate of [How do you add additional files to a nuget package in Visual Studio 2017](https://stackoverflow.com/questions/44498659/how-do-you-add-additional-files-to-a-nuget-package-in-visual-studio-2017) – Bradley Uffner Sep 24 '18 at 02:50

1 Answers1

2

How can I add a Text Template Some.tt file to the package, so it will show up in the referencing project?

You can use the property <Pack>true</Pack> to add the Text Template Some.tt file to the package:

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

Check the document NuGet pack and restore as MSBuild targets for some more details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks. The example is wrong though. The only thing needed to deliver tt as it is to the referencing project is `TextTemplatingFileGeneratorTrue` – Dmitry Nogin Sep 24 '18 at 04:32