The .NET7-Windows project with SourceGenerator e.g. MimeTypes is working. When adding a local namespace to the WPF-UserControl the generated file is not included anymore. How can I modify the project file, that all generated files are automatically included?

Reproducable Example:

Example.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0-windows</TargetFramework>
    <LangVersion>10</LangVersion>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>true</UseWPF>
    <NoWarn>CA1416</NoWarn>
  </PropertyGroup>
  <PropertyGroup>
    <OutputType>Library</OutputType>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="MimeTypes" Version="2.4.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

UserControl1.xaml:

<UserControl x:Class="Example.UserControl1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            >
   <Grid/>
</UserControl>

UserControl1.xaml.cs:

using System.Windows.Controls;

namespace Example
{
   public partial class UserControl1 : UserControl
   {
       public UserControl1()
       {
           InitializeComponent();
           var x = MimeTypes.GetMimeType("Testfile.exe");
       }
   }
}

This is working as expected, but when adding:

            xmlns:local="clr-namespace:Example"

The generated MimeTypes file is not included anymore, which leads to the compiler error CS0103 (The name 'MimeTypes' does not exist in the current context)

0

There are 0 answers