microsoft / microsoft/MSBuildSdks

Can I use the NoTargets SDK to just generate the source?

Open
#579 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
508
Forks
94
Avg merge
6h 40m
Merged PRs (30d)
2

Description

I want to create a project that uses Roslyn Source Generator to generate sources but does not build them.
The purpose is to import the sources generated by this project in another project.
Is this possible?

I wrote the following project and the Generated folder is generated, but the sources are not.

<Project Sdk="Microsoft.Build.NoTargets/3.7.56">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', 'Generated'))</CompilerGeneratedFilesOutputPath>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyGenerator\MyGenerator.csproj">
      <OutputItemType>analyzer</OutputItemType>
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>
  </ItemGroup>

</Project>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Microsoft.Build.NoTargets/3.7.56 SDK targets and the project XML shown in the issue, then trace how the Roslyn source generator is invoked and how EmitCompilerGeneratedFiles is handled. Done means determining whether this project shape can generate reusable source files without building them, and documenting the required configuration or the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.