-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
AssemblyName can not use condition in multiple target frameworks project #22469
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I can confirm that this issue still exists with VS2022. Here are the relevant parts of my csproj:
And here are the exact error messages in English:
|
Another confirmation that this is still broken in VS2022 (17.7.4), but only sometimes. (Yay? 😁) For the broken project, command line I don't know why one works and one doesn't, but hopefully having both will help track down the issue. My
|
I too was having this issue. The issue is with the NuGet restore command through Visual Studio. NuGet appears to use the AssemblyName as part of the Package ID that it generates when doing a restore. The problem comes in when you try to change the AssemlyName conditionally. If you specify your own explicit Package ID then it will fix this problem. Add this property to your property group and set the Package ID to some unique string: |
Thanks you @jeepinpugs! This has saved a tiny part of my sanity! 😄 |
@jeepinpugs You're genius, man. |
cc @dotnet/nuget-team |
This is a known issue, and @jeepinpugs has already described the mitigation, which is to explicitly set the package id. However I strongly recommend against using this pattern. It will cause assembly load failures when 3 or more projects/packages are used: .NET 8 console app reference .NET Standard ClassLib1, which itself references multi-targeting (.NET 8 and .NET Standard) ClassLib2. ClassLib2 will have a compile time reference to ClassLib2.netstandard, but the console app will have ClassLib2.net8.dll in the bin directory. As soon as the console app calls a ClassLib1 API that calls a ClassLib2 API, the runtime will fail with a FileNotFoundException, looking for ClassLib2.netstandard.dll This runtime failure will happen no matter if ClassLib1 and ClassLib2 are packages or project references. The solution to this runtime failure is to keep the assembly name the same for all target frameworks. also see: https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/cross-platform-targeting
|
In addition to the points raised by zivkan, we encountered another problem with having different assembly names for different targets: WPF. (a) XAML requires the name of the assembly when importing namespaces from other assemblies (e.g. Thus, while jeepinpugs' solution works (and the issue mentioned by zivkan's does not apply in our case since we have the mutually incompatible targets .NET 7 and .NET Framework 4.8), we had to go back to using the same assembly name for all targets for our library. |
In that case, I hereby submit the feature request of getting a more helpful error message. :-) |
Someone outside the NuGet team (but still a Microsoft employee) contributed a fix recently:
It'll be improved in VS2022 17.9 preview 3 |
Version Used:
VS2019 16.11.5
Steps to Reproduce:
asdf.csproj
Expected Behavior:
Build success and the condition of AssemblyName work.
Actual Behavior:
Build failed.
The text was updated successfully, but these errors were encountered: