0

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!

CYL
  • 95
  • 1
  • 12

1 Answers1

1

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 >
Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • Thanks! It works. But still one thing I need to fix is that I want the file path in output folder is "MyDll.dll" instead of "files\MyDll.dll". It seems need to modify something... My guess is "PackagePath" but I'm still trying. – CYL Jan 18 '21 at 04:11
  • @CYL, that is right, You should use `PackagePath` to specify the path of the file from the nuget package into the main project. I have updated my answer. – Mr Qian Jan 18 '21 at 07:00
  • 1
    It's fixed now. Thank you very much! – CYL Jan 18 '21 at 07:31