AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 60 forks source link

[0.7.43-alpha] Plugin.Sdk introduces a circular dependency in MSBuild #203

Closed amis92 closed 4 years ago

amis92 commented 4 years ago

Example error: https://github.com/amis92/RecordGenerator/runs/545333929?check_suite_focus=true#step:5:21

NuGet.Build.Tasks.Pack.targets(339,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "_WalkEachTargetPerFramework".

After quick investigation, this is caused by GeneratePackageOnBuild=true in the failing project.

Circular dependency happens because:

To stop the circle, we should set NoBuild=true in TargetsForTfmSpecificContentInPackage when GeneratePackageOnBuild=true - this will stop Publish from depending on Build.

amis92 commented 4 years ago

Until new Plugin.Sdk is published, the workaround in the generator project is as follows:

<Project Sdk="Microsoft.NET.Sdk">
  <Sdk Name="CodeGeneration.Roslyn.Plugin.Sdk" Version="0.7.43-alpha" />
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <TargetsForTfmSpecificContentInPackage>
      _SetNoBuildForGeneratePackageOnBuild;
      $(TargetsForTfmSpecificContentInPackage);
    </TargetsForTfmSpecificContentInPackage>
  </PropertyGroup>

  <Target Name="_SetNoBuildForGeneratePackageOnBuild" Condition=" '$(GeneratePackageOnBuild)' == 'true' ">
    <PropertyGroup>
      <NoBuild>true</NoBuild>
    </PropertyGroup>
  </Target>

</Project>
amis92 commented 4 years ago

Source for Publish dependencies:

https://github.com/dotnet/sdk/blob/61eb83542f4f73ef20766e848b44f674eb9f6333/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L55-L73