我有一个为 x86 编译的旧版 C# 应用程序。我将其升级到 VS 2022,并除了 x86 之外还启用 x64。我想使用 .Net Framework 4.5 编译旧版 x86,使用 .Net 8.0 编译 x64。因此,有效的组合是 x86-.NetFramework4.5 和 x64-.Net6.0。
是否可以根据CPU平台设置TargetFrameworks?
您无法在单个工程文件中直接根据CPU平台设置
TargetFramework
。在
x86
文件中为 x64
和 .csproj
创建单独的配置,并为每个配置指定相应的 TargetFramework
。
例如:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>YourNamespace</RootNamespace>
<AssemblyName>YourAssemblyName</AssemblyName>
<TargetFrameworks>net45;net8.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<TargetFramework>net45</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<TargetFramework>net45</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TargetFramework>net8.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetFramework>net8.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
</Project>
Debug/x86
中的平台(例如,Release/x64
或 Visual Studio
)。Visual Studio
将使用相应的设置中指定的
地产集团。