Design-time race condition with MyProject.GeneratedMSBuildEditorConfig.editorconfig
Version Used: 16.9 or 16.10
Steps to Reproduce:
- Use a source generator that sets msbuild properties to be populated in the
GeneratedMSBuildEditorConfig.editorconfigfile, which detects the presence of design time builds (BuildingProjectisfalse) - 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.
Related: https://github.com/OmniSharp/omnisharp-roslyn/issues/2112
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>
@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?