VS Community 2022仅针对win-x64构建项目及RuntimeIdentifier报错解决
解决VS Community 2022仅构建win-x64目标的问题
先修复添加<RuntimeIdentifier>时的报错
你碰到的"HasTrailingSlash"函数仅接受标量值错误,根源是项目文件里多个OutputPath节点为空(比如<OutputPath></OutputPath>或<OutputPath />),导致MSBuild的内置函数无法处理。先把这些空的OutputPath补上有效值:
找到项目里对应条件的PropertyGroup,修改成:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PlatformTarget>x64</PlatformTarget> <OutputPath>bin\Debug\</OutputPath> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PlatformTarget>x64</PlatformTarget> <OutputPath>bin\Debug\x64\</OutputPath> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PlatformTarget>x64</PlatformTarget> <OutputPath>bin\Release\</OutputPath> </PropertyGroup>
配置仅构建win-x64目标
方法1:直接修改vbproj文件
在第一个全局的<PropertyGroup>(包含TargetFramework的那个)里,添加RuntimeIdentifier配置,同时确保Platforms保持x64:
<PropertyGroup> <OutputType>WinExe</OutputType> <RootNamespace>MyProjectName</RootNamespace> <StartupObject>MyProjectName.frmStart</StartupObject> <UseWindowsForms>true</UseWindowsForms> <MyType>WindowsForms</MyType> <Platforms>x64</Platforms> <TargetFramework>net6.0-windows</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <!-- 添加运行时标识配置 --> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- 若需独立部署可设为true,否则保持false --> <SelfContained>false</SelfContained> </PropertyGroup>
方法2:通过VS图形界面配置(更直观)
- 右键项目 → 属性 → 「生成」选项卡
- 目标平台下拉选择
x64,确保“平台目标”也设为x64 - 切换到「发布」选项卡,点击目标运行时旁的「编辑」按钮
- 选择
Windows→x64,取消勾选“生成所有运行时”选项,保存设置
完成以上操作后,后续构建就只会生成win-x64相关的文件,不会再出现linux、osx等多余目录。
内容的提问来源于stack exchange,提问作者8oris
相关产品推荐
相关产品推荐

