Donate

Using OpenFileDialog Or MessageBox In .NET Core Class Library Project With WPF Application

Good day Team!

Given that you need to access the OpenFileDialog or MessageBox Dialog In Your .NET Core Class Library that is part of a solution that contains a WPF project, there's an easy hack provided by our Solutions Architect that is to hand hack the .csproj settings. First is to open the .csproj file using an editor. Inside Property Group node, add enable WPF by adding a UseWPF element with the value of true such as below.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0-windows10.0.17763.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Company.Utilities.CompanyLibNET7" Version="1.0.0.3" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="Company.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>
Save the .csproj file and rebuild the solution. You should have access to the OpenFileDialog Or MessageBox dialogs in your .NET Core Class Library project.
Output
Using OpenFileDialog Or MessageBox In .NET Core Class Library Project With WPF Application

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid