dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
4.06k stars 862 forks source link

"ResolveComReference" task error when using a new-style csproj #3777

Closed willson556 closed 1 year ago

willson556 commented 5 years ago

DocFX Version Used: docfx.console 2.40.4 with VS Pro 15.9.4

Template used: default

Steps to Reproduce:

  1. Close all instances of MSBuild.exe.
  2. Run build.bat in https://github.com/willson556/DocFXCOMReferenceBug repo.
  3. Observe the following warning in the console output:
    
    Warning:[MetadataCommand.ExtractMetadata](C:/Users/willsont/projects/DocFXCOMReferenceBug/ReferencedApp/ReferencedApp.csproj)Workspace failed with: [Failure] Msbuild failed when processing the file 'C:\Users\willsont\projects\DocFXCOMReferenceBug\ReferencedApp\ReferencedApp.csproj' with message: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2729, 5): Could not run the "ResolveComReference" task because MSBuild could not create or connect to a task host with runtime "CLR4" and architecture "x86".  Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" exists and can be run.
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2749, 7): The "ResolveComReference" task's outputs could not be retrieved from the "ResolvedFiles" parameter. Object does not match target type.

4. Open `procexp.exe` and see several open `MSBuild.exe` processes with Handle to `DocFXComReferenceBug/ReferencedApp`.

**Expected Behavior**:

- DocFX extracts metadata successfully from new-style `.csproj` with a COM Reference.
- Files are not locked at conclusion of CI-build allowing cleanup of CI workspace.

**Actual Behavior**:

- Warning is logged.
- Files are left locked.

**Additional Notes**:

This issue does not occur when using a old-style `.csproj` (without `Sdk` attribute).
I'm not sure how much of this issue falls on MSBuild vs MSBuild.Sdk.Extras vs. DocFX's invocation of MSBuild. I filed the issue here because I figured the DocFX team was better placed than me to answer any follow-up questions the MSBuild team might have. 

One other thing I did notice is that DocFX doesn't pass the `/nr:false` flag along to the MSBuild processes it creates -- we have to set the `MSBUILDDISABLENODEREUSE=1` environment variable.

Possibly Related Issues in other Microsoft Repos:
- https://github.com/dotnet/project-system/issues/4355
- https://github.com/Microsoft/msbuild/issues/3986

Thanks!
willson556 commented 5 years ago

Has anyone had a chance to look into this?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

rapmue commented 5 years ago

I got something similar, also happening with new SDK style projects and regarding ResolveComReference.

But I think it startet with docfx version 2.44.

The error I got is the following:

[19-08-12 09:14:17.192]Warning:[MetadataCommand.ExtractMetadata](XXX.sln)Workspace failed with: [Failure] Msbuild failed when processing the file 'XY.csproj' with message: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2729, 5): Die ResolveComReference-Aufgabe konnte nicht aus "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" instanziiert werden. Die Datei oder Assembly "Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2729, 5): Die "ResolveComReference"-Aufgabe wurde falsch deklariert, falsch verwendet oder konnte bei der Erstellung nicht ausgeführt werden. Überprüfen Sie die Schreibweise des Aufgaben- und des Assemblynamens.

I have no idea why the error message is partly german. It states something like:

The ResolveComReference-task could not be instantiated. The file or assembly "Microsoft.Build" or a dependency could not be found.

and the second part something like:

The ResolveComReference-task is declared wrong, applied wron or could not be executed upon creation. Check the spelling of the task and the assembly name.

The error occurs, when a SDK-style project with COM references is added to the solution.

yufeih commented 1 year ago

It appears the issue was resolved in the latest version:

image