GitHub Actions构建WINUI应用遇NETSDK1134错误求解决
解决GitHub Actions中dotnet build的NETSDK1134错误
问题重现
在GitHub Actions中构建.NET项目时遇到以下错误:
Error: C:\Program Files\dotnet\sdk\7.0.102\Current\SolutionFile\ImportAfter\Microsoft.NET.Sdk.Solution.targets(27,5): error NETSDK1134: Building a solution with a specific RuntimeIdentifier is not supported. If you would like to publish for a single RID, specifiy the RID at the individual project level instead. [D:\a\it_project_testGA\it_project_testGA\InternshipTool.sln]
已检查解决方案内的.csproj文件,未找到<RuntimeIdentifiers>相关配置,当前使用的GitHub Actions配置如下:
name: IT Project InternshipTool on: push: branches: [ "development" ] pull_request: branches: [ "development" ] jobs: build: runs-on: windows-latest steps: - name: Check .NET version run: dotnet --version - name: Checkout code uses: actions/checkout@v2 - name: Install .NET SDK Version uses: actions/setup-dotnet@v3 with: dotnet-version: 6.x.x - name: Restore dependencies run: dotnet restore - name: Build run: dotnet build --configuration Release --runtime win-x64 --property:EnableWindowsTargeting=true - name: Test run: dotnet test --no-build --configuration Release --collect:"XPLAT Code Coverage"
解决方案
1. 移除构建命令中的--runtime参数
dotnet build针对解决方案执行时,不支持直接指定RuntimeIdentifier(RID)。如果你的构建只是为了后续测试,不需要提前绑定特定运行时,可以修改Build步骤的命令:
- name: Build run: dotnet build --configuration Release --property:EnableWindowsTargeting=true
若后续需要发布特定RID的版本,在dotnet publish命令中添加--runtime win-x64即可,比如:
dotnet publish --configuration Release --runtime win-x64 --property:EnableWindowsTargeting=true
2. 直接针对单个项目执行构建
如果必须在构建阶段指定RID,可以跳过解决方案,直接对具体的.csproj文件执行build命令(替换成你项目的实际路径):
- name: Build run: dotnet build ./InternshipTool/InternshipTool.csproj --configuration Release --runtime win-x64 --property:EnableWindowsTargeting=true
3. 在项目文件中配置默认RID
可以在目标项目的.csproj文件中添加RID配置,这样构建解决方案时无需在命令行指定参数:
<PropertyGroup> <RuntimeIdentifier>win-x64</RuntimeIdentifier> </PropertyGroup>
额外注意:SDK版本冲突
错误信息中显示使用的是.NET 7.0.102 SDK,但你的配置里指定安装的是.NET 6.x。这是因为windows-latest虚拟机默认预装了.NET 7,导致实际使用的SDK版本不符合预期。可以在setup-dotnet步骤中指定更精确的版本,比如:
- name: Install .NET SDK Version uses: actions/setup-dotnet@v3 with: dotnet-version: '6.0.406' # 替换为你需要的具体.NET 6版本号
内容的提问来源于stack exchange,提问作者Brutusske
相关产品推荐
相关产品推荐

