0

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?

theBro
  • 66
  • 5
  • I did not know shproj (Shared Projects) existed as a concept. Can these be used in any sort of project? I came here because I am running into an issue where I wanted to reuse some DAL logic in one project in another project, without creating APIs for the two to talk. – John Zabroski Aug 18 '20 at 00:51
  • As far as I understood the shared projects are just a collection of source files which can be included into mutliple other projects. In these other projects the compilation specific configuration takes place e.g. compile definitions, framework settings. But if you add an additional source file to the shared project it is automatically included to all your normal projects via the shared project which is the major benefit in my opinion. – theBro Aug 20 '20 at 07:48

1 Answers1

0

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.

Mikael Dúi Bolinder
  • 2,080
  • 2
  • 19
  • 44
  • I can no longer reproduce this as I have decided to stop using shared projects, but thanks for your effort. – theBro Feb 04 '22 at 08:38