Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] .NET API bug UWP No longer supported #9494

Closed
dotMorten opened this issue Dec 1, 2023 · 10 comments
Closed

[Bug] .NET API bug UWP No longer supported #9494

dotMorten opened this issue Dec 1, 2023 · 10 comments
Labels
bug A bug to fix dotnet: msbuild msbuild integration for .NET API reference docs dotnet Generate .NET API reference docs

Comments

@dotMorten
Copy link
Contributor

dotMorten commented Dec 1, 2023

Describe the bug
Since v2.60.0 we can no longer support UWP and other types of projects that requires the full MSBuild. It seems only .NET Core projects are now supported.

To Reproduce

  1. Create a UWP Class Library with a class in it.
  2. Run metadata command against project with v2.74.1.
  3. Note that no metadata is generated
  4. Repeat with v2.59.4 and notice API metadata is generated

Expected behavior
Metadata gets generated.

Context (please complete the following information):

  • OS: Windows

  • Docfx version: 2.74.1

  • .NET version: .NET Core / UWP

  • docfx.json config

{
  "metadata": [
    {
      "src": [
        {
          "files": [ "ClassLibrary7.csproj" ],
          "src": "E:/sources.tmp/ClassLibrary7/ClassLibrary7"
        }
      ],
      "dest": "api"
    },
  ],
}
  • Errors and warnings
Using .NET Core SDK 8.0.100
Loading project E:/sources.tmp/ClassLibrary7/ClassLibrary7/ClassLibrary7.csproj
warning: [Failure] Msbuild failed when processing the file 'E:\sources.tmp\ClassLibrary7\ClassLibrary7\ClassLibrary7.csproj' with message: The imported project "C:\Program Files\dotnet\sdk\8.0.100\Microsoft\WindowsXaml\v17.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\8.0.100\Microsoft\WindowsXaml\v17.0\Microsoft.Windows.UI.Xaml.CSharp.targets" is correct, and that the file exists on disk.  E:\sources.tmp\ClassLibrary7\ClassLibrary7\ClassLibrary7.csproj
Processing ClassLibrary7
Creating output...
warning: No .NET API detected for ClassLibrary7.


Build succeeded with warning.

    2 warning(s)
    0 error(s)

Output with v2.59.4:

[23-12-01 07:55:59.779]Info:[ExtractMetadata]Using msbuild C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin as inner compiler.
[23-12-01 07:56:01.440]Info:[ExtractMetadata]Loading projects...
[23-12-01 07:56:09.575]Info:[ExtractMetadata]Generating metadata for each project...
[23-12-01 07:56:11.158]Info:Completed in 11717.1026 milliseconds


Build succeeded.
        0 Warning(s)
        0 Error(s)

Additional context
Digging into the compilation, it is now using the '$(MSBuildRuntimeType)'=='Core' which is not supporting these target frameworks.

This is especially a problem when using MSBuildExtras to cross compile for multiple target frameworks, including UWP and Xamarin. MSBuildExtras will generate a build error for these target frameworks:

1>[23-12-01 08:02:39.647]Warning:[ExtractMetadata](E:/GitHub/dotMorten/NmeaParser4/src/NmeaParser/NmeaParser.csproj)Workspace failed with: [Failure] Msbuild failed when processing the file \.nuget\packages\msbuild.sdk.extras\3.0.22\Build\Workarounds.targets: (27, 5): If you are building projects that require targets from full MSBuild or MSBuildFrameworkToolsPath, you need to use desktop msbuild ('msbuild.exe') instead of 'dotnet build' or 'dotnet msbuild'
@dotMorten dotMorten added bug A bug to fix dotnet Generate .NET API reference docs labels Dec 1, 2023
@dotMorten
Copy link
Contributor Author

dotMorten commented Dec 1, 2023

I'm starting to think the reason is because it can't find Visual Studio because that code isn't included in netcoreapp targets:
https://github.com/microsoft/MSBuildLocator/blob/02c357a9554bf91db26d97c32559e03bbae41501/src/MSBuildLocator/MSBuildLocator.cs#L343-L360
Probably this issue here: microsoft/MSBuildLocator#152

@yufeih yufeih added the dotnet: msbuild msbuild integration for .NET API reference docs label Dec 3, 2023
@filzrev
Copy link
Contributor

filzrev commented Dec 13, 2023

As described in linked-issue comment (https://github.com/microsoft/MSBuildLocator/issues/152#issuecomment-1839391035)
It' required to run MSBuild on separate process.

It might be resolved when next Roslyn version(4.9.0) released.
Because MSBuildWorkspace build behavior is changed to running out-of-proc.
https://github.com/dotnet/roslyn/issues/61454#issuecomment-1813193707

@filzrev
Copy link
Contributor

filzrev commented Dec 13, 2023

I've tried to use Roslyn 4.9.0-3.23612.11 (It requires .NET preview NuGet feed).
And It can be successfully running dotnet metadata command.

So this issue will be resolved when Roslyn v4.9.0 is officially released Expected on Feb '24.

@yufeih
Copy link
Contributor

yufeih commented Dec 13, 2023

I've tried to use Roslyn 4.9.0-3.23612.11 (It requires .NET preview NuGet feed). And It can be successfully running dotnet metadata command.

So this issue will be resolved when Roslyn v4.9.0 is officially released Expected on Feb '24.

Nice finding! Out of proc execution solves a whole class of problems with msbuild.

@dotMorten
Copy link
Contributor Author

@yufeih how was this addressed? With 2.76.0 I'm not able to build UWP projects and getting this warning right before all the errors:

warning: [Failure] Msbuild failed when processing the file 'e:\GitHub\dotMorten\NmeaParser\src\NmeaParser\NmeaParser.csproj' with message: If you are building projects that require targets from full MSBuild or MSBuildFrameworkToolsPath, you need to use desktop msbuild ('msbuild.exe') instead of 'dotnet build' or 'dotnet msbuild'

@filzrev
Copy link
Contributor

filzrev commented Apr 23, 2024

If you are building projects that require targets from full MSBuild or MSBuildFrameworkToolsPath, you need to use desktop msbuild ('msbuild.exe') instead of 'dotnet build' or 'dotnet msbuild'

Above message is raised by MSBuildExtras package.
It might be resolved by setting "_SdkIgnoreMSBuildCoreWarning": "true"

@dotMorten
Copy link
Contributor Author

dotMorten commented Apr 24, 2024

@filzrev Thanks I tried that both in the project and in the metadata properties, but no luck. I'm getting the same error for UWP, Xamarin.Android and Xamarin.iOS.
Setting the property does get rid of the warning, but not the error. I think all that warning was doing was warning me about what is about to happen:

warning: [Warning] Unresolved metadata reference removed from project: e:\mscorlib.dll
error: c:\myproject\obj\Release\uap10.0.18362\.NETCore,Version=v5.0.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
error: c:\myproject\obj\Release\uap10.0.18362\NmeaParser.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
error: c:\myproject\obj\Release\uap10.0.18362\NmeaParser.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)

@filzrev
Copy link
Contributor

filzrev commented Apr 25, 2024

On my environment.
Following warning message is displayed before CS0246 errors.

warning: [Failure] Msbuild failed when processing the file 'C:\projects\Rx.NET\Source\src\System.Reactive\System.Reactive.csproj' with message: The specified language targets for uap10.0.18362 is missing. Ensure correct tooling is installed for 'uap'. Missing: 'C:\Program Files\dotnet\sdk\8.0.202\Microsoft\WindowsXaml\v17.0\Microsoft.Windows.UI.Xaml.CSharp.targets'

Above message path indicating .NET SDK version of MSBuild is selected from $(MSBuildExtensionsPath) .
It should use Visual Studio version of MSBuild host instead when generating UWP app metadata.

I've checked how Roslyn 4.9.2 or later execute analysis out-of-process. (dotnet/roslyn#70469)
But can't find ways to change behaviors.

@filzrev
Copy link
Contributor

filzrev commented Apr 26, 2024

But can't find ways to change behaviors.

BuildHost process kind selection logics are hardcoded at https://github.com/dotnet/roslyn/blob/0d1f9fea04892d9e65e9a780bb773a4d5ed18f8e/src/Workspaces/Core/MSBuild/MSBuild/BuildHostProcessManager.cs#L278-L336.

So when using SDK style projects.
.NET SDK version of MSBuild seems used always.


As a workaround.
It can be resolved by manually importing Microsoft.Windows.UI.Xaml.CSharp.targets file when running docfx metadata command for UWP.

Steps

  1. Add following lines at end of NmeaParser.csproj
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets"
          Condition="'$(TargetFramework)' == 'uap10.0.18362' AND '$(DocfxBuild)' == 'true'" />
  1. Edit docfx.config and change settings for UWP metadata generation.
"properties": {
        "TargetFrameworks": "uap10.0.18362",
        "DocfxBuild": "true", 
        "MSBuildExtensionsPath": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\MSBuild"
      },

Note: MSBuild path is depends on VS edition and installed paths.

I don't have Xamarin.Android/Xamarin.iOS build environment thought.
It'll be resolved similar changes.

@dotMorten
Copy link
Contributor Author

dotMorten commented Jul 2, 2024

@filzrev Thanks for this, but unfortunately this isn't a good solution still because of the hardcoded paths to msbuild, and not everyone is using preview, or enterprise, professional or buildtools versions.
I haven't been able to get it to generate metadata for Xamarin.Android or Xamarin.iOS either since this change, and your solution doesn't work for that (with the import path updated for those).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug to fix dotnet: msbuild msbuild integration for .NET API reference docs dotnet Generate .NET API reference docs
Projects
None yet
Development

No branches or pull requests

3 participants