2

For testing purposes, I have an old .Net app with a WinForms GUI that is also a web service, i.e., receives and responds to HTTP messages. While running, it displays received messages and is interactive for querying additional info, etc. This was relatively easy to develop (years ago).

I would like to convert this tool to ASP.NET Core. I have been able to convert a pure WinForms app with no problem, and can create a pure web service, but I have not found a way to combine the two. I need use <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> in the project file to get access to Winforms, but that causes all kinds of 'undefined' errors for things like IWebHostEnvironment, etc.

In short, is there a way to create a web service that also has a local desktop GUI? I think I need both "Microsoft.NET.Sdk.WindowsDesktop" and "Microsoft.NET.Sdk.Web". (Note: I'm not worried about cross-platform portability.)

I've tried adding the following packages, but so far without success:

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.9" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.9" />
    <PackageReference Include="System.Resources.Extensions" Version="4.7.1" />
  </ItemGroup>
Berislav Kovacki
  • 486
  • 4
  • 16
FrankK
  • 41
  • 4
  • Take a look here https://stackoverflow.com/questions/60033762/hosting-asp-net-core-api-in-a-windows-forms-application – ILally Oct 24 '20 at 15:24
  • That's interesting! Thanks! But it's still a .Net Framework app. Can that be converted to .Net Core? – FrankK Oct 24 '20 at 16:21
  • Yes. I converted the packages.config and manually hacked the project file. I now have a .Net Core app with Winforms and a controller. – FrankK Oct 24 '20 at 16:58

1 Answers1

0
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <UseWindowsForms>true</UseWindowsForms>
        <OutputType>WinExe</OutputType>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
        <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
        <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
        <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
        <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.9" />
        <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.9" />
        <PackageReference Include="System.Resources.Extensions" Version="4.7.1" />
    </ItemGroup>

.
.
.
FrankK
  • 41
  • 4