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

Disable copying ProjectReferences in generator projects #74897

Merged

Conversation

ericstj
Copy link
Member

@ericstj ericstj commented Sep 1, 2022

No description provided.

@ghost
Copy link

ghost commented Sep 1, 2022

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

Issue Details

null

Author: ericstj
Assignees: -
Labels:

area-Infrastructure-libraries

Milestone: -

@ericstj
Copy link
Member Author

ericstj commented Sep 1, 2022

Generator projects were getting all referenced projects as ReferenceCopyLocalPaths which causes the referenced library and all satellite assemblies to be copied to the output directory. We also default to including these into binplacing - the process that composes the shared framework layout and ref pack layouts. As a result we had multiple projects trying to copy Microsoft.Interop.SourceGeneration.* to the ref-pack. Two of those - JSImportGenerator.csproj and LibraryImportGenerator.csproj - could build in parallel - which causes a race condition binclash in the build.

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.

Thanks for the quick fix. This shows the power and danger of binplacing into a common directory via a push instead of pull mechanism.

@ViktorHofer ViktorHofer merged commit 6414a0b into dotnet:main Sep 1, 2022
@ViktorHofer
Copy link
Member

/backport to release/7.0-rc1

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2022

Started backporting to release/7.0-rc1: https://github.com/dotnet/runtime/actions/runs/2971758851

@ViktorHofer
Copy link
Member

Backporting as this just happened on a release/7.0 build: https://github.com/dotnet/runtime/pull/74920/checks?check_run_id=8135426753.

@ViktorHofer
Copy link
Member

ViktorHofer commented Sep 1, 2022

@ericstj just double checking, doesn't this mean that the Microsoft.Interop.SourceGeneration.dll dependency of the LibraryImportGenerator.dll doesn't get copied into the targeting pack folder?

<ProjectReference Include="..\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" Pack="true" PackagePath="analyzers/dotnet/cs" />

Asking as Microsoft.Interop.SourceGeneration.dll isn't listed in

LibraryImportGenerator;
(as it's not a source generator project but a helper class lib).

EDIT: Also does this setting have any impact on source generators being packaged?

@ericstj
Copy link
Member Author

ericstj commented Sep 1, 2022

Thanks for the quick fix. This shows the power and danger of binplacing into a common directory via a push instead of pull mechanism.

We have the push tradeoff here because it enables a faster inner-loop for folks - less to rebuild in order to make changes to targeting-pack and test framework. It also enables distributed definition of composition. Both of these were major pieces of feedback we had for years in .NETFramework and DevDiv build - folks hated having to modify "authoring" to define the content of the product and complex set of steps (or full builds) to test. They wanted the definition of the product to be distributed and a local characteristic that they could control in their projects. Probably we can put more guards in place to catch binclashes wherever they might occur for whatever reason to protect us here. That would be a good change regardless since BinClashes can happen for any number of reasons.

Microsoft.Interop.SourceGeneration.dll isn't listed in runtime/src/libraries/NetCoreAppLibrary.props

Yep, that's a problem. We need to explicitly list every binary we want to ship. I'll make a PR that does that.

Also does this setting have any impact on source generators being packaged?

Both LibraryImportGenerator and JSImportGenerator set IsPackable=false. I tried setting IsPackable=true and these were not included in the package. Then I undid this change and tried again - tons of failures since the ProjectReference isn't preserving the resource subdirectory of sattelite dlls in the package.

c:\src\dotnet\runtime\.dotnet\sdk\7.0.100-preview.7.22377.5\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\src\dotnet\runtime\artifacts\bin\Microsoft.Interop.SourceGeneration\Debug\netstandard2.0\zh-Hans\Microsoft.Interop.SourceGeneration.resources.dll' is not added because the package already contains file 'analyzers\dotnet\cs\Microsoft.Interop.SourceGeneration.resources.dll' [C:\src\dotnet\runtime\src\libraries\System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj]
c:\src\dotnet\runtime\.dotnet\sdk\7.0.100-preview.7.22377.5\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\src\dotnet\runtime\artifacts\bin\Microsoft.Interop.SourceGeneration\Debug\netstandard2.0\zh-Hant\Microsoft.Interop.SourceGeneration.resources.dll' is not added because the package already contains file 'analyzers\dotnet\cs\Microsoft.Interop.SourceGeneration.resources.dll' [C:\src\dotnet\runtime\src\libraries\System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj]

Probably these should use the AnalyzerReference mechanism to include them in the package - that handles preserving the subdirectories of the items in the other project through

<_AnalyzerPackFile Include="@(_BuildOutputInPackage)" IsSymbol="false" />
<_AnalyzerPackFile Include="@(_TargetPathsToSymbols)" IsSymbol="true" />
<_AnalyzerPackFile PackagePath="$(_analyzerPath)/%(TargetPath)" />

Since they aren't currently packing, we can just remove this dead-code metadata on the project reference. I'll put that in the PR and then tag you guys to discuss.

@ViktorHofer
Copy link
Member

ViktorHofer commented Sep 1, 2022

Yep, that's a problem. We need to explicitly list every binary we want to ship. I'll make a PR that does that.

Any idea why the omission of that dependent assembly did not result in a build break. Don't we use the live built targeting pack's analyzers?

Probably these should use the AnalyzerReference mechanism to include them in the package

I was more interested in the analyzers that are already shipping inside a package ie the Json and the Extensions one. Are those still being included in their corrrsponding package?

@ericstj
Copy link
Member Author

ericstj commented Sep 1, 2022

I was more interested in the analyzers that are already shipping inside a package ie the Json and the Extensions one. Are those still being included in their corrrsponding package?

Yeah, those don't rely on project references inside the analyzer project to redistribute other projects. They use the AnalyzerReference mechanism from the src project which produces the package.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants