我有一個遺留程式,我正在嘗試從 Net Framework 4.6.1 遷移到 .NET 6。在其中,有一個共享庫需要在 Linux 和 Windows 上運行,以及一些特定于 Windows 的呼叫使用#if NET6_0_WINDOWS 成功隔離。這足以讓 Linux 版本啟動并運行,但是當我嘗試添加 Windows WPF 應用程式時,我遇到了數千個錯誤。為了使 WPF 應用程式保持最新狀態,我運行了升級助手(在此處進行了詳細說明)。不幸的是,如果不付出相當大的努力,該應用程式將無法編譯。
我在 UI 中將我的專案檔案設定為顯式定位視窗(使用 net6.0-windows 作為 TargetFramework),并且我的 xaml 檔案不會與代碼關聯(這是一個常見問題,有很多潛在原因,我是分開的在這里調查使用執行緒。例如,我在 InitializeComponent 上遇到編譯器找不到的錯誤,以及執行緒中提到的錯誤。
更奇怪的是,當我運行應用程式時(經過大量#if NET6_0_WINDOWS 調整),我無法在#if'd 塊中的代碼中設定斷點......我可能會走上一條兔子路,但為什么那個符號是未定義的?
如果相關,正在運行的 WPF 應用程式的專案檔案如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>WPFApp</RootNamespace>
<ApplicationIcon>SoftingIcon.ico</ApplicationIcon>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.*</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<OutputPath>..\bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>..\bin\Release\</OutputPath>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<OutputPath>..\bin\Release\</OutputPath>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup>
<NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup>
<ItemGroup>
<Reference Update="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Update="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Update="UIAutomationProvider">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\EditModel\EditModel.csproj" />
<ProjectReference Include="..\..\common\Tools\Tools.csproj" />
<ProjectReference Include="..\Help\HelpInterface\HelpInterface.csproj" />
<ProjectReference Include="..\ViewPaneLibrary\ViewPaneLibrary.csproj" />
<ProjectReference Include="..\InterfaceControls\InterfaceControls.csproj" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 (x86)</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 (x86)</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
</Project>
uj5u.com熱心網友回復:
前處理器符號僅包括 .Net 版本,不包括 OS(還要小心,NET 和 6 之間沒有下劃線)。
可以在此處找到符號的完整串列: https ://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives
但是,您可以在 MSBuild 中自己定義它。
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0-windows'">
<DefineConstants>$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
</PropertyGroup>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/524942.html
標籤:C#。网wpf移民
上一篇:如何重新排序陣列
下一篇:由于Microsoft.AspNetCore.Hosting.Server.Abstractions與.NET7.0不兼容,我如何在https上托管我的WebApplication?
