Visual Studio 2019
I have a .NET Core
solution that needs to reference a single .NET Framework
package just for the purposes of expanding the package contents into the packages
folder so that some tools are available.
In my .csproj
I have this line :
<PackageReference Include="roundhouse" Version="1.1.0" TargetFramework="net472" />
I'm finding that when I build my solution ( either in local dev Visual Studio
, or TeamCity
) that sometimes NuGet
restores my package to this folder structure :
\packages\roundhouse.1.1.0\roundhouse.1.1.0.nupkg
This is what it's doing currently.
But on another dev machine ( and on TeamCity Build Agent
) the build creates this folder structure :
\packages\roundhouse\1.1.0\roundhouse.1.1.0.nupkg
Notice the slight difference.
I haven't been able to figure out could be causing these different behaviors. I can't find any config setting related to NuGet
package folder-structure.
Does anyone know ?
I think this behavior is related to nuget package format packages.config and PackagesReference.
The global-packages folder(
%userprofile%\.nuget\packages
) is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder. When using the packages.config, packages are installed to the global-packages folder, then copied into the project's packages folder. Hint from here.Conclusion
When you use PackageReference, the path of the nuget which in the global-packages folder is like the structure 2.
Besides, the packages in the solution which is copied from the global-packages folder has changed the path to structure 1.
When you use package.config format, Nuget modifies the path of the nuget which is copied from the global-packages folder to the solution for some specific reasons.
It is just the normal behavior of the package.config and PackagesReference and it is designed by that.
Update1:
I found that you add
<PackageReference Include="roundhouse" Version="1.1.0" TargetFramework="net472" />
into xxx.csproj of a core project. And that format is like the content in the packages.config of a framework project. I guess you just copy the content from packages.config into xxx.csproj of a core project though you use packageReference. Also,TargetFramework="net472"
means that it will install the package onframework4.7.2
, so it will not appear in the core project.l have do these test;
1) Framework project with packages.config
packages.config
xxx.csproj
It loads the packages.config to loads the nuget package
2) Framework project with PackageReference
xxx.csproj
3) Core project
So I think it is the way you imported the nuget package that's causing this strange behavior. And please do not use packages.config format like
TargetFramework="net472"
in a core project(PackageReference).If you make sure that you use PackageReference in all the projects in your solution and you can try the following steps:Solution:
1) clean the nuget cache
2) change your initial reference format in xxx.csproj like
And then you can whether the restore path is different.
Hope it could help you.