novotnyllc / MSBuildSdkExtras

Extra properties for MSBuild SDK projects
MIT License
347 stars 42 forks source link

Issues with modified properties when using dotnet-format #164

Closed GeertvanHorrik closed 5 years ago

GeertvanHorrik commented 5 years ago

I am trying to incorporate dotnet-format (check code style) in our CI builds. However, getting this:

Unhandled exception: System.InvalidOperationException: Cannot modify an evaluated object originating in an imported file "C:\Users\geert\.nuget\packages\msbuild.sdk.extras\2.0.24\Build\Inference.targets".
   at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
   at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0)
   at Microsoft.Build.Evaluation.Project.RemoveProperty(ProjectProperty property)
   at Microsoft.CodeAnalysis.MSBuild.ProjectFile.GetProjectFileInfosAsync(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.DoOperationAndReportProgressAsync[TResult](ProjectLoadOperation operation, String projectPath, String targetFramework, Func`1 doFunc)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectFileInfosAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectInfosFromPathAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress`1 progress, CancellationToken cancellationToken)       
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, IProgress`1 progress, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(ILogger logger, String solutionOrProjectPath, Boolean isSolution, Boolean logAllWorkspaceWarnings, Boolean saveFormattedFiles, ImmutableHashSet`1 filesToFormat, CancellationToken cancellationToken) in /_/src/CodeFormatter.cs:line 58
   at Microsoft.CodeAnalysis.Tools.Program.Run(String workspace, String verbosity, Boolean dryRun, Boolean check, String files, IConsole console) in /_/src/Program.cs:line 89
   at System.CommandLine.Invocation.CommandHandler.GetResultCodeAsync(Object value, InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass3_0.<<InvokeAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<UseParseErrorReporting>b__16_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass3_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<UseSuggestDirective>b__7_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<UseDebugDirective>b__4_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<UseHelp>b__14_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<UseParseDirective>b__6_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<RegisterWithDotnetSuggest>b__17_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Invocation.InvocationExtensions.<>c.<<UseExceptionHandler>b__5_0>d.MoveNext()
An error occurred when executing task 'CleanupCode'.
Error: One or more errors occurred.
        .NET Core CLI: Process returned an error (exit code 1).

Will investigate this (no action required from you) and post updates here.

GeertvanHorrik commented 5 years ago

Happens to this property:

image

clairernovotny commented 5 years ago

This looks like a bug in the MSBuildProjectLoader, I'd open an issue on Roslyn's repo.

GeertvanHorrik commented 5 years ago

Yes, found it, will create a ticket there.

GeertvanHorrik commented 5 years ago

See https://github.com/microsoft/msbuild/issues/4376, will close this ticket since it's out of scope for msbuild sdk extras, but could be a hint for others having the same issue.