-
Notifications
You must be signed in to change notification settings - Fork 252
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
Msbuild pack doesn't choose the right version for ProjectReferences #6379
Comments
@rohit21agrawal looks like pack didn't use assembly version but used default version here |
There is a |
I've tried using both the Version and the PackageVersion elements, neither one worked. |
Last night while converting one of our projects from VS15 to VS17, I happened to notice that a depend nuget package was referencing a project reference dependency correctly. This morning I manually compared the working solution with one that wasn't working. I discovered that the working solution has one very minor difference. The working dependency project included a package called Sure enough, as soon as I added Further investigation shows that it works just by adding the base package Hope this helps. |
Oh, there is one strange side effect to this. The nuget spec for A shows the debug (i.e. prerelease) version number of B regardless of which order I build things. E.g. building Debug then Release or Release and then debug produces the same result. Both Batch file snippet:
After thinking about this I actually like this "feature", that way my dependent's release nuget package Is this by design or is the an artifact of some kind? |
You also need to restore for the right version. the package versions are locked during restore. => See #4337 In your example, I feared that the restore won't see the values of |
@dasMulli I tried your idea of adding restore first, i.e.
and
Either of them worked. However, I just tried another idea, I realized that the dependency projects that are having issues don't include any nuget package references. So, it isn't the fact that I added IOWs, the nuget logic only works if the dependency project has a reference to at least one nuget package. If the dependency project doesn't include any nuget packages then nuget isn't reading the dependency project's version number correctly. Very strange indeed. Hope this helps. |
FYI - as a work-a-round I created an empty nuget package as a place holder, like so:
Where the This works nicely, it doesn't add anything to the project's output etc but it does cause VS and/or nuget to work correctly. |
Ah I see where this is going. As long as there is no package reference, you'll need to set the property <RestoreProjectStyle>PackageReference</RestoreProjectStyle> in classic csproj files. @zhili1208 @rohit21agrawal is just adding an import for the sdk target to a classic project even "supported"? |
@kabua for .NET Framework packages, if you want msbuild-integrated package generation, you will have a better experience using an "sdk-based" project since it sets or defaults all the required properties. You can create a .NET Standard class library and change the |
@dasMulli thanks, adding PackageReference worked! I will also try changing my projects to .NET Standard (which I haven't done before so I'm not sure what I'm getting myself into). We have 12 projects that make up two frameworks that are consumed by several WPF and ASP.NET WebAPI applications. Therefore, can WPF and ASP.NET applications consume .NET Standard libraries? Thanks for the quick responses and help on this. |
Yes those projects can consume .NET Standard libraries. If you need .NET Framework specific functionality in the library packages (e.g. WPF-specific libraries, System.Web namespace) you can still use the new project format and tooling to produce .NET Framework specific packages - there's just no template for this in visual studio, but quite a few open source projects have moved to using this. There's a community slack channel if you need some more help with that (signup at https://tattoocoder.com/aspnet-slack-sign-up/, I have the same username there). |
how can you set the version from command line? I do this with nuget pack now: |
Sounds like the original problem has been long solved. @red8888 You can refer to https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package-dotnet-cli for that |
Details about Problem
Steps to Reproduce
There are two solutions files,
NugetProjectRefTest_Core
andNugetProjectRefTest_Net
, found respectively under the NugetProjectRefTest_Core and NugetProjectRefTest_Net folders.Note: the zip file contains all source, binaries and nuget packages, so no real need to rebuild the solutions.
Back Ground
Each solution folder contains 2 DLLs and 1 console app.
The console app reference
DLL1
as a project reference andDLL1
referenceDLL2
also as a project reference. All 4 DLLs have a nuget version number of8.0.0-Alpha001
.Expected Behavior
That both
CoreDLL1
nuget packages, which depends on their respectiveCoreDLL2
package, reference the correctCoreDLL2
package version number.Actual Behavior
.\NugetProjectRefTest\NugetProjectRefTest_Core\CoreDll1\bin\Debug\CoreDll1.8.0.0-Alpha001.nupkg
, the nuspec dependencies node looks like this:Notice that the
CoreDLL2
version is listed correctly as8.0.0-Alpha001
.Now open the
.\NugetProjectRefTest\NugetProjectRefTest_Net\Packages.Output\NetDll1.8.0.0-Alpha001-Debug.nupkg
, the nuspec dependencies node looks like this:Notice that the
CoreDLL2
version is not listed correct, its showing1.0.0
but is should read:8.0.0-Alpha001
.Sample Project
NugetProjectRefTest.zip
The text was updated successfully, but these errors were encountered: