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

时间:2019-09-25 16:57:19

标签: xamarin azure-devops devops pack

创建了一个Xamarain项目,并创建了Devops(VSTS)管道来构建该项目并将其发布到私有nuget提要。一切都建立得很好,但是打包 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.

2 个答案:

答案 0 :(得分: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 core SDK:

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

希望这会有所帮助。

答案 1 :(得分:0)

所以,我的问题不在我的nuspec文件中。真正的问题归结为使用vmImage:“ macos-latest”,如果您要构建iOS项目(iOS无法在代理程序2019或2017下构建iOS,并且必须使用MSBuild(而非VSBuild)),则需要使用vmImage:“ macos-latest”

macos最新图像有几个问题(我将其称为iOS代理)

  1. 当您引入另一个依赖于它的nuget包时,不包括System.Threading.Task.Extensions(STTE)的nuspec包。如果该软件包位于“ Standard .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 Standard 2.0
  • UWP
  • Android
  • iOS

每个项目,但iOS项目使用VSBuild和2019代理工作;这是淘汰ios代理的过程。

相关问题