New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using PackageReference, NuGet dll's Namespace isn't available in code #7686

Open
agentid36 opened this Issue Jan 10, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@agentid36
Copy link

agentid36 commented Jan 10, 2019

Details about Problem

NuGet product used: VS UI

NuGet version (x.x.x.xxx): 4.6.0

VS version (if appropriate): 15.9.5

OS version (i.e. win10 v1607 (14393.321)): Win7 SP1, fully up-to-date

Worked before? If so, with which NuGet version: No

Detailed repro steps so we can see the same problem

  1. Add https://www.nuget.org/packages/PowerSNMP/ or https://www.nuget.org/packages/PowerSNMP.Standard/
    to a .NET Framework 4.7.2 or .NET Core 2.0 project (respectively) via NuGet (using PackageReference), and attempt to access the 'Dart' namespace in code. I am unable to. When using package.config, I am able to access the namespace.

Full Report:
I'm using Visual Studio 15.9.5; when using PackageReference, or migrating to PackageReference, the namespace of the referenced NuGet package's dll doesn't show up in code (intellisense, etc) in both .NET Framework 4.7.2 and .NET Core 2.0 projects. If I reference the downloaded dll (from bin/debug) (or use package.config) then everything works again (but I'd expect to not need to do this).

This was tested with .NET Framework and .NET Standard dlls under .NET Framework with:
https://www.nuget.org/packages/PowerSNMP/
And .NET Standard dlls under .NET Core 2.0 with:
https://www.nuget.org/packages/PowerSNMP.Standard/

Is there something I'm doing wrong, or is there something required for compatibility with PackageReference that Dart (the manufacturer of the dlls) isn't doing?

@jainaashish

This comment has been minimized.

Copy link
Contributor

jainaashish commented Jan 16, 2019

This seems weird, and should have worked just fine... Couple of follow up questions:

  • were you able to build successfully after installing the package as PackageReference?
  • Did you try restarting your VS?
  • Do you see a obj/project.assets.json file after installing the package as PackageReference?
  • Do you see the NuGet package reference in dependency Node in Solution Explorer window?
@agentid36

This comment has been minimized.

Copy link

agentid36 commented Jan 16, 2019

Thanks for your comments.

  1. If there's no code that references the NuGet dll's namespace (Dart), yes. If there is, no.
  2. Restarting VS2017 does not resolve this.
  3. Yes. The relevant sections appear to be (from a Windows Forms 4.7.2 project):

"version": 3,
"targets": {
".NETFramework,Version=v4.7.2": {
"PowerSNMP/4.10.0": {
"type": "package",
"compile": {
"lib/net45/.": {}
},
"runtime": {
"lib/net45/Dart.Snmp.45.dll": {}
}
}
},
".NETFramework,Version=v4.7.2/win": {
"PowerSNMP/4.10.0": {
"type": "package",
"compile": {
"lib/net45/.": {}
},
"runtime": {
"lib/net45/Dart.Snmp.45.dll": {}
}
}
},
".NETFramework,Version=v4.7.2/win-x64": {
"PowerSNMP/4.10.0": {
"type": "package",
"compile": {
"lib/net45/.": {}
},
"runtime": {
"lib/net45/Dart.Snmp.45.dll": {}
}
}
},
".NETFramework,Version=v4.7.2/win-x86": {
"PowerSNMP/4.10.0": {
"type": "package",
"compile": {
"lib/net45/.": {}
},
"runtime": {
"lib/net45/Dart.Snmp.45.dll": {}
}
}
}
},
"libraries": {
"PowerSNMP/4.10.0": {
"sha512": "LS5cYYNZWRh4AaMq1lg+zdL8BuzmBbEiw8hwgUn+jYkRhPY4tBhx6kaXaw4eBhwsZPoZ8lrhCEWD2YXGhqgoTA==",
"type": "package",
"path": "powersnmp/4.10.0",
"hasTools": true,
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/net4/Dart.Snmp.dll",
"lib/net4/Dart.Snmp.xml",
"lib/net45/Dart.Snmp.45.dll",
"lib/net45/Dart.Snmp.45.xml",
"powersnmp.4.10.0.nupkg.sha512",
"powersnmp.nuspec",
"tools/Init.ps1",
"tools/Resources/titleLeft.jpg",
"tools/Resources/titleRight.jpg",
"tools/readme.html"
]
}
},
"projectFileDependencyGroups": {
".NETFramework,Version=v4.7.2": [
"PowerSNMP >= 4.10.0"
]
},

From a .NET Core console project:

  "PowerSNMP.Standard/4.10.0": {
    "type": "package",
    "compile": {
      "lib/netstandard2.0/_._": {}
    },
    "runtime": {
      "lib/netstandard2.0/Dart.Snmp.Standard.dll": {}
    }
  }


"PowerSNMP.Standard/4.10.0": {
  "sha512": "v+8v58sesiot0IaGe08sw2Af2HLLyGCNPWedN2j7m1JV3wV5JZ37uWRoVv4GzG7smGJVGiA5jgDAwpV93pHlYQ==",
  "type": "package",
  "path": "powersnmp.standard/4.10.0",
  "hasTools": true,
  "files": [
    ".nupkg.metadata",
    ".signature.p7s",
    "lib/netstandard2.0/Dart.Snmp.Standard.deps.json",
    "lib/netstandard2.0/Dart.Snmp.Standard.dll",
    "powersnmp.standard.4.10.0.nupkg.sha512",
    "powersnmp.standard.nuspec",
    "tools/Init.ps1",
    "tools/Resources/titleLeft.jpg",
    "tools/Resources/titleRight.jpg",
    "tools/readme.html"
  ]
}
  1. Yes, mostly. When in a Windows Forms project, it's under the 'References' project node, with the blue NuGet icon, as 'PowerSNMP'. When in a .NET Core 2.0 Console project, it's under the 'Dependencies\NuGet' node as 'PowerSNMP.Standard (4.10.0)' (it's a different package), with a greyscale NuGet icon.
@jainaashish

This comment has been minimized.

Copy link
Contributor

jainaashish commented Jan 16, 2019

ohh I see the package PowerSNMP is marked as developmentDependency in it's .nuspec file which is why when installed through PackageReference it doesn't get any compile time assets. So when you see in the assets file, compile time assets are empty...

".NETFramework,Version=v4.7.2": {
"PowerSNMP/4.10.0": {
"type": "package",
"compile": {
"lib/net45/.": {}
},
"runtime": {
"lib/net45/Dart.Snmp.45.dll": {}
}
}
},

Ideally you shouldn't override this behavior since package author created this package only for build time dependency but if you want to override it then you can use PrivateAssets=none on this PackageReference to consume it at compile time as well. something like:

<PackageReference Include="PowerSNMP">
      <Version>4.10.0</Version>
      <PrivateAssets>none</PrivateAssets>
 </PackageReference>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment