-
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
Targeting net5.0-windows still causes 'API X is supported on windows' errors #14502
Comments
I think I managed to trace the issue down. The problem seems to be caused by the fact that we have a shared project (shproj) in our solution and this shared project contains our <PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" />
</ItemGroup> And this seems to be interfering with the This theory seems to be further supported by the following minimal repro: The repro is a trivial console app with TFM set to
This should work regardless whether I generate an assembly info or create it manually. Otherwise users can get into a situation where they are targeting |
We experience the same issue with our code. We use a shared AssemblyInfo.cs file in our projects, and
on net5.0-windows |
@yevgeni-zolotko Until this is properly resolved, you can work around the issue by putting |
@mareklinka Thank you, the following worked for me:
|
Is there an ETA on an official fix for this? We're having the same issues in our projects. |
#if NET5_0
[assembly: System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif removes only |
@kirsan31 The parameter in [assembly: System.Runtime.Versioning.SupportedOSPlatform("windows7.0")] Disclaimer: I have not tested this behavior so your mileage may vary. |
Thank you, I've already tried and this is not helped :( Also I am not understand why Overall if I build user control with P.s. I've completely disabled |
I was able to get this to go away by moving all my [assembly:] to csroj using . Unfortunately the parameters for those need to be strings (out of the box anyway: dotnet/msbuild#2281 (comment)). |
@kirsan31 I've added just the following and only the following be sure not to add after adding Adding both only removes only the windows warning but not the Windows 7.0 warning. Adding the first removes both. |
I have the same issue with the project below. This line of code will give warning CA1416:
|
@Epic-Santiago because you disabled generating AssemblyInfo.cs |
@dsplaisted @sfoslund is it possible to add the |
I would suggest one of the following for projects:
|
Thanks for the feedback. Adding the SupportedOSPlatform("windows") assembly attribute works. But there's a bit more nuance to this issue. Because if I don't include We can look at migrating to a props or target file. As you correctly guessed above, we use a shared AssemblyInfo so that we have common attributes across thousands of projects. We've been doing this for a long time, well before SDK-style projects required disabling |
Weird, |
It's warning about the registry. But if I remove the AspNetCore framework reference, I don't have the issue. See my sample project above. You can trivially repro the issue. Then remove the |
If we are targeting net5.0-windows, shouldn't |
The mechanism by which it is implicit involves automatically generating the |
Old bug triage: Per Daniel's comment above, there is a workaround by setting the assembly attribute directly:
or turning back on GenerateAssemblyInfo. |
Hello. I have a project migrated from netcoreapp3.1 to net5.0 that references the System.DirectoryServices 5.0.0 nuget. This nuget targets Windows only (the assembly is marked with
[assembly: SupportedOSPlatform("windows")]
):So trying to compile that project with TFM
net5.0
errors out with CA1416:According to the documentation for that rule (emphasis mine):
From that I surmised that switching the project file to target
net5.0-windows
should be enough to compile the project. Unfortunately, this is not the case - I'm still getting the CA1416 violations.My csproj:
dotnet build
still caused CA1416 errors. When I add[assembly: SupportedOSPlatform("windows")]
to the assembly, it compiles correctly. So either the documentation for rule CA1416 is wrong or something is not working correctly with thenet5.0-windows
TFM. Or I'm missing something crucial here.Can you please take a look at this?
EDIT
I should have mentioned that I'm using the current GA versions of dotnet 5.0 SDK:
The text was updated successfully, but these errors were encountered: