-
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
AOT compile gives incorrect error about Roslyn source generator coming from a ProjectReference #37228
Comments
We need to get clarity if this is caused by passing If it is passed on the command line, then this is very likely the same problem as described in dotnet/runtime#94406. |
I've run into the same issue in a project, and it's as you describe above, with the following in my csproj: <PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
<PublishAot>true</PublishAot>
</PropertyGroup> and using the command With the command
|
Unfortunately, as described above, this is an expected behavior right now. Passing the property on the command line "forces" the property on all projects, including dependent library projects. |
@vitek-karas What's the recommended way to produce 2 builds, one AOT'd and one not, without resorting to modifying the |
You can introduce conditionals into the project: <PublishAot Condition="'$(MyPublishWithoutAot)' != 'true'">true</PublishAot> And then on command line: This will produce the AOT build
This will produce a non-AOT build
|
Thanks @vitek-karas, tho I found mirroring the value to be more... canonical? <PublishAot Condition="'$(ProjectPublishAot)' != ''">$(ProjectPublishAot)</PublishAot> |
I intentionally made it to default to PublishAOT - because this property also enables analyzers during build/IDE, and if the app is supposed to be AOT ready then it should use the analyzers by default. |
Ah, I slapped |
It appears there's a bug in the SDK's enforcement around project references and AOT compile. If you're doing an AOT compile, all the dependencies are checked for being a valid TFM for AOT, which 100% makes sense. However if a user is consuming a Roslyn source generator from another project (which folks often do), that project is also being checked even though we enforce that Roslyn source generators must be compiled as netstandard2.0. Note the generator in this case is being ran not as a part of deployed app but as a part of the build, so AOT shouldn't be applying in the first place.
I'd say the bug in this case would be that a project reference that's marked as ReferenceOutputAssembly="false" or OutputItemType="Analyzer" shouldn't be getting considered for purposes of AOT. I'm not sure exactly where that condition check should go but I'd expect it to be somewhere.
Discussed in dotnet/roslyn#70900
Originally posted by rudiv November 20, 2023
We have a test project that references our source generator:
This works fine until we try to compile as AOT, it is trying to compile the source generator too which obviously fails due to the netstandard2.0 target.
The Source Generator is marked as a Roslyn Component and works in other scenarios for AOT (ie. referenced from NuGet).
What is the correct way to test this? Our generator is designed to produce code that makes the project AOT friendly, but we would obviously like the ability to test this.
The workaround we're using now is to compile the source generator first, get the nupkg and create a target that references this local package. However that seems cumbersome.
The text was updated successfully, but these errors were encountered: