roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Design-time race condition with MyProject.GeneratedMSBuildEditorConfig.editorconfig

Open jeromelaban opened this issue 4 years ago • 3 comments

Version Used: 16.9 or 16.10

Steps to Reproduce:

  1. Use a source generator that sets msbuild properties to be populated in the GeneratedMSBuildEditorConfig.editorconfig file, which detects the presence of design time builds (BuildingProject is false)
  2. Build the project and have the design-time builds run simultaneously

Expected Behavior: Design-time builds don't interfere with the main build.

Actual Behavior: The main build may fail because the BuildingProject is false where it should be try.

Additional information

This kind of optimization is useful to determine whether to avoid generating extended and expensive source during design-time. It looks like the GeneratedMSBuildEditorConfig.editorconfig is shared for both build types and can get mixed depending on the build type.

This issue is even more visible on vscode with omnisharp, where there may be even less synchronization between command line builds and design-time builds.

jeromelaban avatar Mar 10 '21 03:03 jeromelaban

Related: https://github.com/OmniSharp/omnisharp-roslyn/issues/2112

chsienki avatar Mar 11 '21 22:03 chsienki

Here's a quick and dirty workaround:

  <Target Name="Roslyn51768Workaround" BeforeTargets="BeforeBuild">
       <CreateProperty Value="$(IntermediateOutputPath)$(MSBuildProjectName).d$(DesignTimeBuild)-b$(BuildingProject).GeneratedMSBuildEditorConfig.editorconfig">
            <Output
                TaskParameter="Value"
                PropertyName="GeneratedMSBuildEditorConfigFile" />
        </CreateProperty>
  </Target>

jeromelaban avatar Nov 02 '21 02:11 jeromelaban

@chsienki Do you think the issue here is that simply the task inputs are not reflected in target inputs?

https://github.com/dotnet/roslyn/blob/b0b4061b8210ce3bdba3581db0646211ede15990/src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets#L169-L171

https://github.com/dotnet/roslyn/blob/b0b4061b8210ce3bdba3581db0646211ede15990/src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets#L192-L193

So basically once the file is written, the target is seen as up to date and is incorrectly skipped?

Youssef1313 avatar Jun 20 '23 06:06 Youssef1313