【问题标题】:bitbucket pipeline with c# fails使用 c# 的 bitbucket 管道失败
【发布时间】:2022-10-05 15:55:58
【问题描述】:

所以我想让我在 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


    【解决方案1】:

    WPF 仅限于 Windows 操作系统: https://docs.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 管道在 Linux 上运行的主要问题。因此,基本上您正在尝试在 Microsoft 不支持的 Linux 上构建 WPF 应用程序。

    【讨论】:

      【解决方案2】:

      点网核心框架已安装。 在这个框架内,有几个用于不同目的的“运行时”,您可以通过以下方式枚举:

      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]

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

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

      经过:

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

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

      <UseWindowsForms>true</UseWindowsForms>
      

      在您推送并检查该管道通过后,投票!和subscribe to my Youtube Channel !

      【讨论】:

        猜你喜欢
        • 2020-02-04
        • 1970-01-01
        • 2018-12-19
        • 2021-11-03
        • 2018-08-29
        • 1970-01-01
        • 1970-01-01
        • 2019-01-18
        • 2019-07-06
        相关资源
        最近更新 更多