microsoft / MSBuildSdks

MSBuild project SDKs
MIT License
460 stars 82 forks source link

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

Open aetos382 opened 1 month ago

aetos382 commented 1 month ago

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>