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

Exclude generated files from compilation by default #77325

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kasperk81
Copy link
Contributor

Set ExcludeGeneratedFilesFromCompilation to true by default if not explicitly specified by updating Microsoft.CSharp.Core.targets to automatically exclude all .cs files in CompilerGeneratedFilesOutputPath.

This prevents duplicate type definitions and build errors when running dotnet build multiple times.

Fix dotnet/sdk#47046

@kasperk81 kasperk81 requested a review from a team as a code owner February 24, 2025 13:14
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 24, 2025
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Feb 24, 2025
Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

Don't believe this is the best path forward here. Generally not in favor of a new property that replaces a single line of msbuild.

@kasperk81
Copy link
Contributor Author

it is about overall experience.

this uses default location (obj/somewhere/) which is excluded

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

with custom location

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>mylocation</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

we have duplicate definition error. is that the intended experience? if so, quite strange!

@jaredpar
Copy link
Member

In this case though you're using a custom location which is part of the included paths searched for source files. My push back is why are you doing that? This is a documented location that the compiler searches for source files. There are plenty of other tasks in the sdk that generate code, or even content, and none of them are being pushed to be excluded in this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Exclude CompilerGeneratedFilesOutputPath from Compilation by Default
3 participants