Search code examples
c#.netasp.net-corenuget

How to access contentFiles of referenced Nuget package?


In the scenario in question, I have two assemblies.

Assembly A: holds the necessary files which are contained in the resulting NuGet package as content

    <PropertyGroup>
        <AssemblyName>MyAssemblyNamespace.Reporting</AssemblyName>
    </PropertyGroup>

  <ItemGroup>
    <Content Include="ReportTemplates/**/*.*">
      <IncludeInPackage>true</IncludeInPackage>
    </Content>
  </ItemGroup>

Assembly B: References the NuGet package 'as normal'

      <ItemGroup>
        <PackageReference Include="MyAssemblyNamespace.Reporting" />
      </ItemGroup>

How can I obtain the files as Stream? They are located as Content in the referenced NuGet package? NuGet Package Explorer shows the files under \content and \contentFiles

Many thanks in advance!


Solution

  • You just need to set PackageCopyToOutput to true. After you build the project, the ReportTemplates folder will be copied to the output folder. If you want to further specify the output path, configure the PackageOutputPath attribute. Don't forget to increase the package version to ensure that your updates work.

    <Content Include="ReportTemplates/**/*.*">
        <IncludeInPackage>true</IncludeInPackage>
        <PackageCopyToOutput>true</PackageCopyToOutput>
    </Content>