dotnet 5 的 WPF 调度程序

时间:2021-07-08 11:41:36

标签: c# wpf .net-5

我们正在将 .net framework 4.7 迁移到 .net 5。我们工作的项目是一个 WPF 项目,我们需要使用 WPF 的 Dispatcher 类。

在 .net framework 4.7 中,我们包含了 using System.Windows.Threading; 和参考 WindowsBase,但我们不能在 .net 5 中做同样的事情。

你知道是什么导致了这种奇怪的行为吗?

提前致谢。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <OutputType>Library</OutputType>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <CodeAnalysisRuleSet>..\.sonarlint\ccsharp.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Productive|AnyCPU'">
    <OutputPath>bin\Productive\</OutputPath>
    <DefineConstants>PRODUCTIVE;TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <CodeAnalysisRuleSet>..\.sonarlint\ccsharp.ruleset</CodeAnalysisRuleSet>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="C">
      <HintPath>..\Files\C.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <None Include="..\.sonarlint\ccsharp.ruleset">
      <Link>ce-terminalcsharp.ruleset</Link>
    </None>
    <None Include="..\Files\Log4Net.config">
      <Link>Log4Net.config</Link>
    </None>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="log4net">
      <Version>2.0.8</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.70" />
    <PackageReference Include="Microsoft.Windows.Compatibility" Version="5.0.2" />
    <PackageReference Include="RestSharp">
      <Version>106.6.10</Version>
    </PackageReference>
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
    <PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.2.233001">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <AdditionalFiles Include="..\.sonarlint\SonarLint.xml">
      <Link>SonarLint.xml</Link>
    </AdditionalFiles>
  </ItemGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>
</Project>

1 个答案:

答案 0 :(得分:4)

System.Windows.Threading.Dispatcher 当然在 .NET 5 中可用。

如果您正在创建类库,项目文件应如下所示:

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

  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>