aleczandru
aleczandru

Reputation: 5469

Missing static file from nuget package on install

I am trying to include a global configuration file in my nuget package. This is what I have so far:

In my csproj I have the following:

 <ItemGroup>
      <Content Include="appsettings.infrastructure.json">
          <Pack>true</Pack>
          <PackagePath>contentFiles;content</PackagePath>
          <IncludeInPackage>true</IncludeInPackage>
          <CopyToOutput>true</CopyToOutput>
          <BuildAction>Content</BuildAction>
          <copyToOutput>true</copyToOutput>
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          <CopyToPublishDirectory>Always</CopyToPublishDirectory>
      </Content>
  </ItemGroup>

If I publish the package locally and unzip it I can see the file exists under contentFile folder.

The problem appears after I install my nuget package in a project. If I check bin/debug/netcoreapp3.1 I expected to see appsettings.infrastructure.json there but it is not there.

I have also tryed to do a file system search in the project folder but there does not seem to be any appsettings.infrastructure.json file saved anywhere.

Does anyone know what I can do to get this file in the bin/Debug/netcoreapp3.1 from a nuget package?

Upvotes: 1

Views: 656

Answers (1)

aleczandru
aleczandru

Reputation: 5469

In the end I was able to achieve what I needed using the following configuration:

  <ItemGroup>
      <None Update="appsettings.infrastructure.json" 
            Pack="true" 
            PackagePath="contentFiles\any\any;content">
          <PackageCopyToOutput>true</PackageCopyToOutput>
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          <CopyToPublishDirectory>Always</CopyToPublishDirectory>
      </None>
  </ItemGroup>

Upvotes: 4

Related Questions