NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

Create a x86+x64 .NET 4.6+Native nuget library and it's driving me NUTS #9369

Open jessehouwing opened 4 years ago

jessehouwing commented 4 years ago

Details about Problem

I've been trying to craft a nuspec file (to be used with nuget.exe pack) to create a nupack that has the following elements:

All of these target net46 and above.

I've created a reference assembly as well by now.

This is what the nuspec looks like:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyProject.Core</id>
    <dependencies>
      <group targetFramework="net46">
        <dependency id="log4net" version="2.0.8" />
        <dependency id="Newtonsoft.Json" version="7.0.1" />
        <dependency id="CSLA-Core" version="4.5.501" />
      </group>
    </dependencies>
    <references>
      <group targetFramework="net46">
        <reference file="MyProject.Reporting.dll" />
        <reference file="MyProject.dll" />
        <reference file="DotNetOpenAuth.dll" />
      </group>
    </references>
  </metadata>
  <files>
    <file src="../../Application/Bin/API/DotNetOpenAuth.dll" target="lib/net46" />

    <!--<file src="tools/Install.ps1" target="tools" />-->

    <file src="../../Application/Components/mvldes32.dll" target="runtimes/win-x86/native" />
    <file src="../../Application/Components/mvldes64.dll" target="runtimes/win-x64/native" />
    <file src="../../MyProject/bin/$configuration$/x64/ref/MyProject.dll" target="ref/net46" />
    <file src="../../MyProject/bin/$configuration$/x86/MyProject.dll" target="runtimes/win-x86/lib/net46" />
    <file src="../../MyProject/bin/$configuration$/x64/MyProject.dll" target="runtimes/win-x64/lib/net46" />

    <file src="../../MyProject.Reporting/bin/$configuration$/x64/ref/MyProject.Reporting.dll" target="ref/net46" />
    <file src="../../MyProject.Reporting/bin/$configuration$/x64/MyProject.Reporting.dll" target="runtimes/win-x64/lib/net46" />
    <file src="../../MyProject.Reporting/bin/$configuration$/x86/MyProject.Reporting.dll" target="runtimes/win-x86/lib/net46" />
  </files>

</package>

I can't get the references to MyProject.Reporting.dll and MyProject.dll to appear in the editor after adding the nuget file.

nuget pack complains it can't find the assemblies:

Error NU5018: Invalid assembly reference 'MyProject.dll'. Ensure that a file named 'MyProject.Reporting.dll' exists in the lib directory.
Error NU5018: Invalid assembly reference 'MyProject.dll'. Ensure that a file named 'MyProject.dll' exists in the lib directory.

I've searched all over and have stumbled upon many similar questions, but everyone seems to get stuck on the exact pieces of the puzzle on this problem. It looks as if it may be working for .NET Core and UWP from what I gather from the samples and the docs, but I'm not entirly sure of that either.

NuGet version: 5.5.0.6473 VS version (if appropriate): 2019 OS version (i.e. win10 v1607 (14393.321)): win10 2004 19041.172

Detailed repro steps so we can see the same problem

See above nuspec

Other suggested things

All multi-platform examples here show UWP: https://github.com/NuGet/docs.microsoft.com-nuget/blob/master/docs/create-packages/Supporting-Multiple-Target-Frameworks.md Similar issues linked to the docs page: https://github.com/NuGet/docs.microsoft.com-nuget/issues?utf8=%E2%9C%93&q=%22d70bd2f5-c04b-9207-62a0-4ecb6e8e5ca6%22&in=body Docs page: https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks Many similar questions on Stackoverflow with all kinds of solutions, but none seem to come close to what these docs suggest... https://www.bing.com/search?q=nuget+package+x86+x64+site%3astackoverflow.com

jessehouwing commented 4 years ago

Or should the guidance here really be: create 2 nuget packages.

  1. x86
  2. x64
cheenamalhotra commented 4 years ago

@jessehouwing

Do you have a sample app? I wonder how can one conditionally provide Dependencies for Platform specific targets. There's no "Platform" attribute supported in NuSpec too.

jessehouwing commented 4 years ago

In the end I converted the whole project to AnyCPU with dynamic library loading and got rid of the platform specific build outputs.

ArsenijK commented 3 years ago

@jessehouwing how did you do that? I.e. we want to make a Nuget package, that has both x86 and x64 dlls in it, and BOTH should be built, and then .NET assembly, which checks dynamically if it's running x86 or x64 and loads one of those dll to use. We have a problem to creating a nuget, that has both dlls, which get copied to the build folder (/bin/Debug/ or Release or whatever) for the end user, who adds our Nuget. Could you please share, how to correctly pack that for .NET STANDART?

jessehouwing commented 3 years ago

I did this at a client and no longer have access to that codebase. Sorry.

If I remember correctly we ended up with an any cpu project with the dotnet any put assemblies in them, a content folder with a x64 and an x86 folder with the respective native binaries in them.

A piece of MS build target file to copy the binaries to the output directory.

On Fri, 2 Apr 2021, 12:07 ArsenijK, @.***> wrote:

@jessehouwing https://github.com/jessehouwing how did you do that? I.e. we want to make a Nuget package, that has both x86 and x64 dlls in it, and BOTH should be built, and then .NET assembly, which checks dynamically if it's running x86 or x64 and loads one of those dll to use. We have a problem to creating a nuget, that has both dlls, which get copied to the build folder (/bin/Debug/ or Release or whatever) for the end user, who adds our Nuget. Could you please share, how to correctly pack that for .NET STANDART?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NuGet/Home/issues/9369#issuecomment-812465523, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA724S5D3UT4GY3T4NCX5CLTGWJNLANCNFSM4LYBRAGA .