【问题标题】:Is it possible to publish a Xamarin project to a private nuget package feed in VSTS (DevOps)是否可以将 Xamarin 项目发布到 VSTS(DevOps)中的私有 nuget 包源
【发布时间】:2019-09-28 00:39:25
【问题描述】:

创建了一个 Xamarain 项目,并创建了一个 Devops (VSTS) 管道来构建项目并将其发布到私有 nuget 源。一切都很好,但是 Pack nuget 包的步骤失败了。

1) 我的第一次尝试是使用“Macos-latest”在解决方案上执行 msbuild@1。 Nuget 安装程序使用 nuspec 文件进行打包。打包步骤出现错误

2)然后我尝试做一个 VSBuild@1,然后是一个 DotNetCoreClI@2,但没有成功。

3) 我还尝试将 3 个项目(iOS、Android、UWP)拆分为 3 个独立的作业,但它们在打包步骤中也失败了。

4)我尝试了各种技术打包,nuspec文件,csproj文件都没有成功。

我的 YAML 文件如下所示:

'
- task: NuGetToolInstaller@1 
   displayName: 'Install nuget.exe 4.4.1'
   inputs:      
     versionSpec: 4.4.1'

- task: NuGetCommand@2
  displayName: "restore the ble solution"
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    vstsFeed: '$(packageFeedName)'

- task: MSBuild@1
  displayName: 'Build BLE solution'
  inputs:
    solution: "**/*.sln"
    configuration: '$(buildConfiguration)'      
    msbuildArguments: '/p:OutputPath=$(outputDirectory) /p:JavaSdkDirectory="$(JAVA_HOME)/"'

- task: NuGetCommand@2
  displayName: "pack nuget"
  inputs:
    command: pack
    packagesToPack: './myproject.nuspec'
    packDestination: '$(Build.ArtifactStagingDirectory)'
    versioningScheme: byEnvVar
    versionEnvVar: 'nugetVersion'
    includeSymbols: true

'

我使用 nuspec 文件总是归结为相同的路径问题。

Attempting to build package from 'BLE.nuspec'. 

[error]The nuget command failed with exit code(1) and error(Could not find a part of the path /Users/vsts/agent/2.155.1/work/1/s/Plugin.BLE/bin/Release/netstandard2.0.

System.IO.DirectoryNotFoundException: Could not find a part of the path /Users/vsts/agent/2.155.1/work/1/s/Plugin.BLE/bin/Release/netstandard2.0.

当我为包使用 **/*.csproj 时,我得到:

Build FAILED.
d:\a\1\s\Plugin.BLE.Android\Plugin.BLE.Android.csproj" (pack target) (1:2) ->d:\a\1\s\Plugin.BLE.Android\Plugin.BLE.Android.csproj(94,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.2.105\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. 
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

【问题讨论】:

    标签: xamarin azure-devops devops pack


    【解决方案1】:

    是否可以将 Xamarin 项目发布到 VSTS (DevOps) 中的私有 nuget 包源

    答案是肯定的。这取决于您要生成多少个包。

    如果你想为 3 个项目(iOS、Android、UWP)创建一个 nuget 包,你应该使用.nuspec 文件。

    路径问题是因为您没有在.nuspec 文件中设置正确的路径。 .nuspec 文件应设置在.sln 文件所在下一级的文件夹中。 dll的路径是.nupsec文件所在的相对路径。

    所以,路径应该是这样的:

    <files>
        <!-- Cross-platform reference assemblies -->
        <file src="XamarinDemo\bin\Release\XamarinDemo.dll" target="lib\netstandard2.0\XamarinDemo.dll" />
        <file src="XamarinDemo\bin\Release\XamarinDemo.xml" target="lib\netstandard2.0\XamarinDemo.xml" />
    
        <!-- iOS reference assemblies -->
        <file src="XamarinDemo.iOS\bin\Release\XamarinDemo.dll" target="lib\Xamarin.iOS10\XamarinDemo.dll" />
        <file src="XamarinDemo.iOS\bin\Release\XamarinDemo.xml" target="lib\Xamarin.iOS10\XamarinDemo.xml" />
    
        <!-- Android reference assemblies -->
        <file src="XamarinDemo.Android\bin\Release\XamarinDemo.dll" target="lib\MonoAndroid10\XamarinDemo.dll" />
        <file src="XamarinDemo.Android\bin\Release\XamarinDemo.xml" target="lib\MonoAndroid10\XamarinDemo.xml" />
    
        <!-- UWP reference assemblies -->
        <file src="XamarinDemo.UWP\bin\Release\XamarinDemo.dll" target="lib\UAP10\XamarinDemo.dll" />
        <file src="XamarinDemo.UWP\bin\Release\XamarinDemo.xml" target="lib\UAP10\XamarinDemo.xml" />
    </files>
    

    查看文档Create packages for Xamarin with Visual Studio 2015了解一些详细信息。

    如果要为每个平台创建三个 nuget 包,可以使用 **/*.csproj 包。

    问题的原因是您需要在构建项目/解决方案之前安装 .NET 核心 SDK:

    - task: UseDotNet@2
      displayName: 'Use .Net Core sdk 2.2.105'
      inputs:
        version: 2.2.105
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      所以,我的问题不在我的 nuspec 文件中;真正的问题归结为使用 vmImage :“macos-latest”,如果您想构建 iOS 项目,这是必需的(iOS 不会在代理 2019 或 2017 下构建,您必须使用 MSBuild(不是 VSBuild)

      macos-latest 镜像有几个问题(我将其称为 iOS 代理)

      1. 当您引入另一个依赖于它的 nuget 包时,不包括 System.Threading.Task.Extensions (STTE) 的 nuspec 包。如果包在“标准.net 2.0项目”中,那么STTE包必须包含在标准项目和ios项目中;这只发生在ios代理中。

      2. 我用于解决方案路径 $(solution) 的变量没有扩展为 myproj.sln;日志将路径显示为 /$($solution) 并且项目未构建,没有警告或错误表明构建了零个项目;我测试的任何其他代理类型均未出现此问题。

      3. ios 代理的 Xamarin sdk 严重过时,必须进行设置。

      需要 yaml:

      variables:
        mono: 5_18_1
        xamarinSDK: 12_8_0_2
      
      
      - task: Bash@3
          displayName: "Set xamarinSDK to version $(mono)"
          inputs:
            targetType: 'inline'
            script: /bin/bash -c "sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh $(mono)"
      

      用于解决此问题的技术是将 Xamarin 项目拆分为 4 个单独的项目并将它们作为单独的项目发布:

      • .Net 标准 2.0
      • UWP
      • 安卓
      • iOS

      除 iOS 之外的每个项目都使用 VSBuild 和 2019 代理;然后是 ios 代理上的淘汰过程。

      【讨论】:

        猜你喜欢
        • 2013-01-09
        • 2022-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-30
        相关资源
        最近更新 更多