dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.83k stars 9.84k forks source link

Generated OpenApi source not included in build if WPF Window exists in project. #34795

Open programatix opened 2 years ago

programatix commented 2 years ago

Describe the bug

OpenAPI Service Reference generated code is not included during build when System.Windows.Window object exists in project.

To Reproduce

  1. Create a Core Console project.
  2. Add OpenAPI service reference.

    
    <Project Sdk="Microsoft.NET.Sdk">
    
    <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>
    
    <ItemGroup>
    <OpenApiReference Include="OpenAPIs\swagger.json" CodeGenerator="NSwagCSharp">
      <SourceUri>https://mysite/swagger/v1/swagger.json</SourceUri>
    </OpenApiReference>
    </ItemGroup>
    
    <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="NSwag.ApiDescription.Client" Version="13.0.5">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>

3. Create an object for the swagger client in Program.cs

var httpclient = new HttpClient(); var a = new swaggerClient("https://mysite/", httpclient);

4. Build. It should be successful.
5. Convert the console project to WPF project.
WinExe net5.0-windows true https://mysite/swagger/v1/swagger.json all runtime; build; native; contentfiles; analyzers; buildtransitive all runtime; build; native; contentfiles; analyzers; buildtransitive
6. Add ```App.xml```.
7. Move the swagger client creation to ```App.xml```.
8. Build and it should build successfully.
9. Add a ```Window (WPF)```
10. Build and and build fail with error ```error CS0246: The type or namespace name 'swaggerClient' could not be found (are you missing a using directive or an assembly reference?)```.

### Exceptions (if any)
```error CS0246: The type or namespace name 'swaggerClient' could not be found (are you missing a using directive or an assembly reference?)```

### Further technical details
- VS 2019 version 16.10.4

PM> dotnet --info .NET SDK (reflecting any global.json): Version: 5.0.302 Commit: c005824e35

Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.302\

Host (useful for support): Version: 5.0.8 Commit: 35964c9215

.NET SDKs installed: 3.1.411 [C:\Program Files\dotnet\sdk] 5.0.104 [C:\Program Files\dotnet\sdk] 5.0.203 [C:\Program Files\dotnet\sdk] 5.0.205 [C:\Program Files\dotnet\sdk] 5.0.302 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]



Attached is the sample project which should build successfull. To reproduce the issue, just add a new ```Window (WPF)``` and build will fail.
[ConsoleApp1.zip](https://github.com/dotnet/aspnetcore/files/6892028/ConsoleApp1.zip)
rafikiassumani-msft commented 2 years ago

Triage: We will re-evaluate this issue during .NET7 planning.

ghost commented 1 year ago

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

NSchertler commented 1 year ago

I am experiencing the same problem in one of my projects. I could narrow down the problem to what appears to be a XAML namespacing issue. As soon as there is a XAML file with a clr-namespace in it (xmlns:local="clr-namespace:..."), compilation will fail with the aforementioned error.

A simple workaround is to create a class library that contains the <OpenApiReference> and reference the class library from the WPF project. This will let you use the generated code from WPF as well.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

SteffenMangold commented 1 week ago

I am experiencing the same problem in one of my projects. I could narrow down the problem to what appears to be a XAML namespacing issue. As soon as there is a XAML file with a clr-namespace in it (xmlns:local="clr-namespace:..."), compilation will fail with the aforementioned error.

A simple workaround is to create a class library that contains the <OpenApiReference> and reference the class library from the WPF project. This will let you use the generated code from WPF as well.

This indeed helped. Thanks! :)