使用 C# 的 bitbucket 管道失败

问题描述 投票:0回答:2

所以我想让托管在 bitbucket 上的 c# 成功运行管道。在我的本地 Windows 机器上,发布和调试构建一切正常。

yml 文件的第一个版本

image: mcr.microsoft.com/dotnet/core/sdk:3.1

pipelines:
 default:
   - parallel:
       - step:
           name: Build and Test
           caches:
             - dotnetcore
           script:
             - REPORTS_PATH=./test-reports/build_${BITBUCKET_BUILD_NUMBER}
             - dotnet restore
             - dotnet build --no-restore --configuration Release
             - dotnet test --no-build --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml"
       - step:
           name: Lint the code
           caches:
             - dotnetcore
           script:
             - export SOLUTION_NAME=GameEnhancer
             - export REPORTS_PATH=linter-reports
             - dotnet new tool-manifest
             - dotnet tool install JetBrains.ReSharper.GlobalTools
             - dotnet tool restore
             - dotnet jb inspectcode ${SOLUTION_NAME}.sln --output="${REPORTS_PATH}/jb-${BITBUCKET_BUILD_NUMBER}.xml"
           artifacts:
             - linter-reports/**

和 .csproj 文件:

<Project Sdk="Microsoft.NET.Sdk">

 <PropertyGroup>
   <OutputType>WinExe</OutputType>
   <TargetFramework>netcoreapp3.1</TargetFramework>
   <UseWPF>true</UseWPF>
   <StartupObject>GameEnhancer.App</StartupObject>
 </PropertyGroup>

 <ItemGroup>
   <PackageReference Include="Ookii.Dialogs.Wpf" Version="3.1.0" />
   <ProjectReference Include="..\GameEnhancer.Core\GameEnhancer.Core.csproj" />
 </ItemGroup>

</Project>

收到此错误:

dotnet build --no-restore --configuration Release
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/3.1.416/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(349,5): warning NETSDK1107: Microsoft.NET.Sdk.WindowsDesktop is required to build Windows desktop applications. 'UseWpf' and 'UseWindowsForms' are not supported by the current SDK. [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
 GameEnhancer.Core -> /opt/atlassian/pipelines/agent/build/GameEnhancer.Core/bin/Release/netcoreapp3.1/GameEnhancer.Core.dll
/usr/share/dotnet/sdk/3.1.416/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognized [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
Build FAILED.
/usr/share/dotnet/sdk/3.1.416/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(349,5): warning NETSDK1107: Microsoft.NET.Sdk.WindowsDesktop is required to build Windows desktop applications. 'UseWpf' and 'UseWindowsForms' are not supported by the current SDK. [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
/usr/share/dotnet/sdk/3.1.416/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognized [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
   1 Warning(s)
   1 Error(s)

当前.csproj文件:

<Project Sdk="Microsoft.NET.Sdk">

 <PropertyGroup>
   <OutputType>WinExe</OutputType>
   <TargetFramework>netcoreapp3.1</TargetFramework>
   <UseWPF>true</UseWPF>
   <StartupObject>GameEnhancer.App</StartupObject>
   <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
   <MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);NETSDK1107</MSBuildWarningsAsMessages>
 </PropertyGroup>

 <ItemGroup>
   <PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.0" />
   <ProjectReference Include="..\GameEnhancer.Core\GameEnhancer.Core.csproj" />
   <PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
   <KnownFrameworkReference Update="Microsoft.WindowsDesktop.App.WPF" IsWindowsOnly="false" />
 </ItemGroup>
 
</Project>

当前错误:

AssemblyInfo.cs(3,12): error CS0246: The type or namespace name 'ThemeInfoAttribute' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
AssemblyInfo.cs(3,12): error CS0246: The type or namespace name 'ThemeInfo' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
AssemblyInfo.cs(4,5): error CS0103: The name 'ResourceDictionaryLocation' does not exist in the current context [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
AssemblyInfo.cs(7,5): error CS0103: The name 'ResourceDictionaryLocation' does not exist in the current context [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
Partial/InjectConfigForm.xaml.cs(2,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(10,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(11,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(13,22): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(14,22): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameSelector.xaml.cs(8,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/MainMenu.xaml.cs(4,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/ModInfoEditor.xaml.cs(5,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/NewGameForm.xaml.cs(4,22): error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
MainWindow.xaml.cs(8,39): error CS0246: The type or namespace name 'Window' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
App.xaml.cs(8,32): error CS0246: The type or namespace name 'Application' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
Partial/InjectConfigForm.xaml.cs(10,45): error CS0246: The type or namespace name 'UserControl' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/MainMenu.xaml.cs(11,37): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameSelector.xaml.cs(15,41): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/MainMenu.xaml.cs(22,57): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
DialogUtility.cs(38,40): error CS0246: The type or namespace name 'UIElement' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/MainMenu.xaml.cs(41,54): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/ModInfoEditor.xaml.cs(12,42): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameSelector.xaml.cs(51,17): error CS0246: The type or namespace name 'Button' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/NewGameForm.xaml.cs(11,40): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameSelector.xaml.cs(65,57): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/NewGameForm.xaml.cs(38,56): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/NewGameForm.xaml.cs(44,54): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/NewGameForm.xaml.cs(51,53): error CS0246: The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(21,41): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(61,56): error CS0246: The type or namespace name 'DragEventArgs' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
View/GameModsMenu.xaml.cs(95,16): error CS0246: The type or namespace name 'UIElement' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
   0 Warning(s)
   31 Error(s)

注意事项: 所以不知何故它无法使用 System.Windows 包。

这些行似乎没有什么区别:

   <PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
   <KnownFrameworkReference Update="Microsoft.WindowsDesktop.App.WPF" IsWindowsOnly="false" />

没有这行:

<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>

错误将是:

dotnet build --no-restore --configuration Release
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
 GameEnhancer.Core -> /opt/atlassian/pipelines/agent/build/GameEnhancer.Core/bin/Release/netcoreapp3.1/GameEnhancer.Core.dll
/usr/share/dotnet/sdk/3.1.416/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognized [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
Build FAILED.
/usr/share/dotnet/sdk/3.1.416/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognized [/opt/atlassian/pipelines/agent/build/GameEnhancer/GameEnhancer.csproj]
   0 Warning(s)
   1 Error(s)
c# wpf .net-core continuous-integration bitbucket-pipelines
2个回答
1
投票

WPF 仅限于 Windows 操作系统: https://learn.microsoft.com/en-us/answers/questions/19216/wpf-in-linux.html

根据此博客(https://devblogs.microsoft.com/dotnet/announcing-net-5-0-preview-1/),.NET Core 和 .NET 5(最新的 .NET 平台)将支持WPF。但看起来支持仅限于 Windows 操作系统。

bitbucket pipeline在Linux上运行的主要问题。所以,基本上你正在尝试在 Microsoft 不支持的 Linux 上构建 WPF 应用程序。


1
投票

dot net core框架已安装,但还显示:

NETSDK1107: Microsoft.NET.Sdk.WindowsDesktop is required to build Windows desktop 

在这个框架内有几个用于不同目的的“运行时”,您可以通过以下方式枚举:

dotnet --list-runtimes

以我为例,我有:

>dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Microsoft 没有告诉您的是 csproj 本身应该针对正确的运行时。因此,在 csproj 的第一行,您应该替换:

<Project Sdk="Microsoft.NET.Sdk">

作者:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

如果您还没有这样做,最后添加:

<UseWindowsForms>true</UseWindowsForms>

在您推送并检查管道通过后。

© www.soinside.com 2019 - 2024. All rights reserved.