MSBuild pack nuget package with files from folder

24 Views Asked by At

I have a project which produces a library and then a post build script creates a needed license file. Afterwards, all files needed are copied into one folder (MyFolder) in a different project. This project's single purpose is to pack all the files and subdirectories in "MyFolder" and pack it into a nuget package. The whole content of "MyFolder" should be unpacked in the root directory.

My .csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <PackageId>SomeId</PackageId>
    <Company>MyCompany</Company>
    <Product>MyProduct</Product>
    <Version>1.0.0</Version>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="MyFolder\**" PackageCopyToOutput="true">
      <Pack>true</Pack>
      <PackagePath>\content</PackagePath>
    </Content>
  </ItemGroup>

</Project>

When I run the pack command, the nuget package is created and all the files appear in the package in the "Content" folder. But, when I install the nuget package, the subdirectories and the license file are not unpacked to the root folder. How can I achieve that?

0

There are 0 best solutions below