摘要:
- 工程從.NET Framework 4.8升級(jí)到.NET 8.0,即使采用官方方案也是很繁瑣的一件事情,而且容易出問(wèn)題。
- Windows 11內(nèi)置了.NET Framework 4.8,所以當(dāng)前的軟件需要基于.NET Framework 4.8。但后續(xù)微軟推出Windows 12,將內(nèi)置更高版本的.NET版本,如何讓軟件跟隨微軟步伐快速平穩(wěn)升級(jí)?
- 本文叫你如何打破微軟封印,在VS2022中如何高屋建瓴面向未來(lái)優(yōu)雅地創(chuàng)建.NET Framework 4.8工程。
關(guān)鍵工作流程:
- 創(chuàng)建新項(xiàng)目,【W(wǎng)PF 應(yīng)用程序】
- 選擇框架【.NET 8.0(長(zhǎng)期支持)】
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-765710.html
- 基于.NET 8.0的工程文件【HAPTICCAL.csproj】
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<RootNamespace>FirstSolver</RootNamespace>
<ApplicationIcon>$(AssemblyName).ico</ApplicationIcon>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<Authors>秦建輝</Authors>
<AssemblyVersion>4.3.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NeutralLanguage>zh-Hans</NeutralLanguage>
<StartupObject>FirstSolver.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="C2VColorEdit" Version="3.0.0" />
<PackageReference Include="C2VLanguage" Version="3.0.0" />
<PackageReference Include="HPSocket.Net" Version="5.9.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLogHelper" Version="3.0.0" />
<PackageReference Include="NLogViewer" Version="3.0.0" />
<PackageReference Include="TF_Communication_CS" Version="3.0.4" />
</ItemGroup>
<ItemGroup>
<Resource Include="..\TF.png" Link="TF.png" />
<Resource Include="$(AssemblyName).ico" />
</ItemGroup>
<ItemGroup>
<None Update="Languages\en-US\$(AssemblyName).json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Languages\zh-Hans\$(AssemblyName).json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Languages\zh-Hant\$(AssemblyName).json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="$(AssemblyName)_Config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell.exe -ExecutionPolicy RemoteSigned -Command "&'$(ProjectDir)PostBuild.ps1' '$(TargetDir)' '$(ProjectPath)' '$(AssemblyName)'"" />
</Target>
</Project>
- 如圖所示更改工程文件【HAPTICCAL.csproj】,重點(diǎn):TargetFramework改成TargetFrameworks
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-765710.html
- 新的工程文件【HAPTICCAL.csproj】
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net480</TargetFrameworks>
<UseWPF>true</UseWPF>
<RootNamespace>FirstSolver</RootNamespace>
<ApplicationIcon>$(AssemblyName).ico</ApplicationIcon>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<Authors>秦建輝</Authors>
<AssemblyVersion>4.3.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NeutralLanguage>zh-Hans</NeutralLanguage>
<StartupObject>FirstSolver.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="C2VColorEdit" Version="3.0.0" />
<PackageReference Include="C2VLanguage" Version="3.0.0" />
<PackageReference Include="HPSocket.Net" Version="5.9.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLogHelper" Version="3.0.0" />
<PackageReference Include="NLogViewer" Version="3.0.0" />
<PackageReference Include="TF_Communication_CS" Version="3.0.4" />
</ItemGroup>
<ItemGroup>
<Resource Include="..\TF.png" Link="TF.png" />
<Resource Include="$(AssemblyName).ico" />
</ItemGroup>
<ItemGroup>
<None Update="Languages\en-US\$(AssemblyName).json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Languages\zh-Hans\$(AssemblyName).json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Languages\zh-Hant\$(AssemblyName).json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="$(AssemblyName)_Config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="PowerShell.exe -ExecutionPolicy RemoteSigned -Command "&'$(ProjectDir)PostBuild.ps1' '$(TargetDir)' '$(ProjectPath)' '$(AssemblyName)'"" />
</Target>
</Project>
- 出現(xiàn)異常,然后【卸載項(xiàng)目】,再【重新加載項(xiàng)目】。
- 面向未來(lái)升級(jí)到.NET 8.0只需要修改“net480”,將“net480”改為“net8.0-windows”即可。
到了這里,關(guān)于打破微軟封印面向未來(lái)創(chuàng)建.NET Framework4.8工程的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!