theBro
theBro

Reputation: 66

Why are PackageReference's references not working for msbuild and shared projects?

After migrating from packages.config to PackageReferences (.NET4.5 Project) the build (msbuild) is broken.

error CS0246: The type or namespace name 'anynugetpackage' could not be found (are you missing a using directive or an assembly reference?)

Building with VisualStudio works perfectly. So I did a little research and found out that the restore of the packages also works fine with msbuild.

The problem only exists for shared projects (.shproj) where the reference of the PackageReference is not applied correctly.

A workaround is to add a fix reference to the PackageReference's lib, but like this I lose all advantages of PackageReference compared to the packages.config

You can have a look at the project and the different solutions (branches):

packages.config
PackageReference
PackageReferenceWorkaround

For build and errorlog see github actions.

Is there any better way to handle it?

Upvotes: 0

Views: 1005

Answers (1)

Mikael Dúi Bolinder
Mikael Dúi Bolinder

Reputation: 2285

Adding the ProjectReference to .projitems does work.

The .shproj isn't imported by the .csproj. Double-check the .csproj to see which file is actually imported.


I'd suggest using a separate project file for package references that can be added to the solution. Visual Studio doesn't do it well, it'll ask if you want to overwrite the file if edited externally and doesn't let me add the .projitems as a solution item.

Upvotes: 0

Related Questions