Search code examples
c#visual-studionugetproject-referencepackagereference

Visual Studio: Copy files into output with their package


I have a project called "A" project, and it contain some files (like dll or others).

In my main project, I used "Project Reference" to reference this project, and add some context into the .csproj of A as follow:

<ItemGroup>
    <ContentWithTargetPath Include="files\MyDll.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        <TargetPath>MyDll.dll</TargetPath>
    </ContentWithTargetPath>
</ItemGroup>

It's looked fine and the files were always copied to the output folder of my main project.

But after I make A project become a Nuget package and my main project use "Package Reference" to reference it, the files in A project are gone in output folder of my main project.

Does have any way to deal with it?

Thanks!


Solution

  • Instead, you should use:

    <PackageCopyToOutput>true</PackageCopyToOutput>
    

    Check this issue.

    Update

    Use this instead:

    <Content Include="files\MyDll.dll" Pack="true" PackagePath="contentFiles\any\any\MyDll.dll;content\MyDll.dll">
              <PackageCopyToOutput>true</PackageCopyToOutput>
    </Content >