-
Notifications
You must be signed in to change notification settings - Fork 257
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
[Bug]: props and targets files are not imported from build folder of transitive dependencies if custom platform name is used #11253
Comments
Hey @sigurn, The build folder is not transitive by default, please see: https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets. What do you actually need from the build targets for B? You've got options for sure.
Closing this given that it's really a question not a bug, but I'd be happy to help you narrow down your issue. |
Thank you very much for the fast reply. The main problem here is that backward compatibility is broken between NuGet versions. Switching the same project to new MSBuild/NuGet version makes it unbuildable. Build targets from B contains scripts for installer like
I considered it as a bug for several reasons:
|
@nkolev92 Do you have any ideas, suggestions? |
Oh my bad. Apparently comments on closed issues where I'm not tagged end up in a different folder. Not sure what you mean by platform here. When you put something after net472, that makes it a profile, which means more specific than net472.
Why do you think you need to do this?
Can you help me understand what in particular doesn't work in VS 2019, but works in VS2017?
Same question as above applied.
I think a repro would be great! Thanks! |
@nkolev92 here is repository which reproduces the issue |
Hi @nkolev92! Did the project help to understand the issue? Any ideas how to solve the issue? |
In my opinion, this is by design. With .NET 5, the Target Framework specification changed, in particular, there's now a In versions of NuGet before we added support for I believe this explains why you're seeing the |
@zivkan We have a product which consists of many modules (every module is a NuGet package). So there are dependencies which are needed just in build time, there are dependencies which are needed in runtime and there are dependencies which we need to build deployment packages. Every module (NuGet package) has pieces for deployment and there is separate list of dependencies which are needed for deployment package (i.e. MSI). There are actually several deployment packages there are standalone installers, update packages, etc. So we use such TargetFrameworks for managing those dependencies. |
@zivkan any ideas how to solve this problem? |
I am OK with using something like
|
I'm not sure this would achieve what you would want it to, but you could upvote this issue: #7900. Or maybe this issue: #5154 For a package where you only want for compile not runtime (copied to bin folder), you can use If you control the packages themselves, you can author them differently, so this behavior is automatic, rather then requiring the package consumer to do the work. Packages that contain compile-time only assets, should have them in Or maybe using MSBuild's Choose-When-Otherwise syntax could get you what you need: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditional-constructs?view=vs-2019 Unfortunately your project/package was using Target Frameworks that were never valid (never appeared in any supported Target Framework list), and we don't have plans to change this at this time. |
@zivkan Could you explain why with VS2019 if packages and project use TargetFramework |
The last version of NuGet without |
@zivkan I don't think that piece of code is related. I don't use
it installs both packages PackageA and PackageB. So command line nuget works as expected whereas MSBuild works differently. This leads me to a conclusion that there is something wrong in how MSBuild uses NuGet. Do you know if there is a way to make it work the same as command line nuget? |
That code I linked is exactly what is used in PackageReference restore (and maybe packages.config in Visual Studio). It doesn't matter that you're using some custom proj file, rather than a typcial csproj, vcxproj, fsproj, vbproj. If Microsoft.Common.props is being imported (via whatever SDK the project uses), that's the code that figures out what target frameworks the project uses.
MSBuild's "contract" for how target framework is defined, has always been the TargetFrameworkMoniker, TargetFrameworkIdentifier, and TargetFrameworkVersion properties. TargetFramework was a short version for convenience that NuGet was always doing "wrong", and had to be fixed to support net5.0. Now that NuGet has fixed this issue, it's possible to do silly things like: <Project Sdk="Microsoft.Net.Sdk">
<PropertyGroup>
<TargetFramework>AnythingIWant</TargetFramework>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>5.0</TargetFrameworkVersion>
<TargetFrameworkMoniker>$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
</PropertyGroup>
</Project> This will now work. Due to a design flaw in NuGet's assets file format, it's not possible to have multiple target frameworks use the same canonical TFM (the issue to implement "TF as alias" would fix that). The TargetFramework MSBuild property is only parsed if the TFM, TFI and TFV properties are not set, but in that case we can't guarantee behaviour of non-valid framework names. Think of it like C/C++ language "undefined behavior". |
@zivkan I understand your point about validation but if
That is exactly our case we just use MSBuild for building installer no assemblies building or so. And we expect that restore will just restore packages without any extra validation. Just the same as command line NuGet does. Does it make sense? Don't you think that current inconsistent behavior makes some mess? |
It appears that the .NET SDK does not support automatic inference of .NET Framework profiles, and that customers are explicitly required to set the TargetFrameworkIdentifier, Version and Profile values. If you'd like MSBuild and/or the .NET SDK to infer these values, and error out when it's not supported, you'll need to create issues in https://github.com/dotnet/msbuild or https://github.com/dotnet/sdk. I validated that NuGet's Microsoft.Build.NoTarget is supported by an independent team, their repo is at https://github.com/microsoft/MSBuildSdks/ for issues specific to those SDKs. |
@zivkan, Wow! Thank you very much for the information. It really did the trick and now, when I set TargetFrameworkProfile explicitly, everything works as expected. Thanks a lot for the help. |
NuGet Product Used
MSBuild.exe
Product Version
MSBuild: 16.11.0.36601, NuGet: 5.11.0
Worked before?
MSBuild: 15.9.21.664, NuGet: 4.9.3
Impact
I'm unable to use this version
Repro Steps & Context
msbuild.exe /nologo /t:Restore SomeProject.proj
I expect:
SomeProject.nuget.g.props file has imports of props files from both packages:
In fact:
SomeProject.nuget.g.props file has imports from PackageA only:
Verbose Logs
No response
The text was updated successfully, but these errors were encountered: