0

I try to build and install nuget pack with c# proxy for c++ dll. So, when I install my pack to target project with Visual Studio 2019, it seems, that install is success. But I not see my c++ dll copied from nuget content to in project folder. My first version of nuget pack used build/Install.ps1, and it copied success my c++ dll to target project folder, but.. not for all projects. For example, when in VS2019 Nuget Package Manager I checked mark for target project with name like ProjectName - all is OK, Install.ps1 execute. But sometime projects in Nuget Package Manager have names like ProjectName\ProjectName.csproj - unfortunately, Install.ps1 not executed for such projects. This why I should to return to use targets files for copying. Ok, I created target file, pack my nuget packet and install it with VS2019 Nuget Package Manager. C++ dll not copied, but, repeat, packet was installed success. This is content of installed packed in solution package dir:

- Comp.Dep.NetClient.2.3.1
- build
 - netstandard2.0
   - Comp.Dep.NetClient.targets
   - Comp.Dep.NetClient.props
   - c++.dll (need to be copy to target project folder)
- lib
 - netstandard2.0
   - c#.dll (client proxy, added to project references)
- Comp.Dep.NetClient.2.3.1.nupkg 

I tried many kinds of Comp.Dep.NetClient.targets content. I try to use Comp.Dep.NetClient.props instaed. Nothing help :) dll not copied. Now, my Comp.Dep.NetClient.targets and Comp.Dep.NetClient.props has next content:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
    <None Include="@(NativeLibs)">
      <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

I used different kinds from this https://qastack.ru/programming/19478775/add-native-files-from-nuget-package-to-project-output-directory ..and from this How can I set the 'copy to output directory' property in my nuspec file? ..and others :) nothing work.. For example, my target project structure after install pack is next:

  • Solution dir
    • packages
      • Comp.Dep.NetClient.2.3.1
        • ..(see structure on previous example)
    • MyApp.sln
    • MyApp (project dir)
      • MyApp.csproj
      • ...other files, but not c++ dll I expect that after install my nuget to MyApp project is success, my c++ dll will be copied to MyApp (project dir). But it not happens. Why??!!
  • OK, I've found solution ) Just put necessary dll in nuget Content directory, as described here https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package, and it was copied to SolutionDir\ProjectDir\ root directory – Taras Kolomiets Nov 25 '21 at 13:29
  • Well, and solution with Content folder not working for projects with "double" name like ProjectName\ProjectName.csproj in VS2019 Nuget Package Manager.. Package is installed success, but dll is not copied to project dir..Bug? – Taras Kolomiets Nov 25 '21 at 14:14
  • Final point of problem research is https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference#package-compatibility-issues – Taras Kolomiets Nov 26 '21 at 06:54
  • So, my investigation stopped on ContentFiles dir instead of Content and .targets file - all this solutions are not working.. To this moment I don;t know how to get VS copy files to folder of project with PackageReference type of packages management. But I revert packagereference to packages.config like this https://www.softwaremeadows.com/posts/revert_packagereference_project_to_packages_config/ and now nuget works corectly – Taras Kolomiets Nov 26 '21 at 10:55

0 Answers0