Skip to content
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

Set AnyCPU for ProjectReference to source generators #103819

Closed
wants to merge 1 commit into from

Conversation

huoyaoyuan
Copy link
Member

The source generators are built with AnyCPU. When opening CoreLib in Visual Studio, it tries to load source generators from platform dependent path since CoreLib is platform dependent, and the generators are not in the solution.

An alternative approach is to include them in corelib.sln.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 21, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 21, 2024
@huoyaoyuan huoyaoyuan added area-Infrastructure-libraries and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 21, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging we should double check that this doesn't cause double writes or overbuilds. Also cc @ericstj

@@ -56,15 +56,18 @@
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj"
ReferenceOutputAssembly="false"
OutputItemType="Analyzer"
SetPlatform="Platform=AnyCPU"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AaronRobinsonMSFT
Copy link
Member

/cc @jkoritzinsky

@huoyaoyuan
Copy link
Member Author

Before merging we should double check that this doesn't cause double writes or overbuilds.

Any instruction to decide this? Inspecting a binlog from full build?

@ViktorHofer
Copy link
Member

The only projects that need this are the ones that set a platform that isn't AnyCPU, right? If so then I think it would be better to tell those projects to not flow the platform to referenced projects.

AFAIK that's the property that handles this: https://github.com/dotnet/msbuild/blob/c028e44472dde6a62689a1378d3ee649f903275a/src/Tasks/AssignProjectConfiguration.cs#L120-L125

VS defaults this to true but we already set it to false in runtime:

<!-- Propagate the configuration and platform to project references. When building in VS, this defaults to true.

Any idea why the platform still gets propagated? And yes, the corelib solution files need to be closure complete (meaning that all project references need to be part of the solution file).

@huoyaoyuan
Copy link
Member Author

Any idea why the platform still gets propagated?

This answered why it worked fine for me previously. The setting was lifted from libraries in #91873 and became applicable to corelib. It seems that the purpose was to unset Configuration. /cc @vitek-karas

And yes, the corelib solution files need to be closure complete (meaning that all project references need to be part of the solution file).

This may also solve the problem in VS. Not sure whether we still need the SetPlatform, but ensuring generators are always AnyCPU looks more correct.

@ViktorHofer
Copy link
Member

Closing in favor of #104561. Thanks for your contribution anyway.

@ViktorHofer ViktorHofer closed this Jul 9, 2024
@huoyaoyuan huoyaoyuan deleted the generator-anycpu branch July 9, 2024 13:08
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Infrastructure-libraries community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants