简体   繁体   English

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

[英]Is it possible to publish a Xamarin project to a private nuget package feed in VSTS (DevOps)

A Xamarain project was created and a Devops (VSTS) pipeline was created to build and publish the project to a private nuget feed.创建了一个 Xamarain 项目并创建了一个 Devops (VSTS) 管道来构建项目并将其发布到私有 nuget 源。 Everything builds great, but the step that would Pack the nuget package fails.一切都很好,但是打包nuget package 的步骤失败了。

1) My first attempt was to use the "Macos-latest" to do an msbuild@1 on the solution. 1) 我的第一次尝试是使用“Macos-latest”在解决方案上执行 msbuild@1。 The Nuget installer uses a nuspec file to do the packing. Nuget 安装程序使用 nuspec 文件进行打包。 An error show's up in the packing step包装步骤中出现错误

2) I then tried to do a VSBuild@1, followed by a DotNetCoreClI@2 without success. 2)然后我尝试做一个 VSBuild@1,然后是一个 DotNetCoreClI@2,但没有成功。

3) I also attempted to split the 3 projects (iOS, Android, UWP) into 3 separated jobs but they failed in the packing step too. 3)我还尝试将 3 个项目(iOS、Android、UWP)拆分为 3 个单独的作业,但它们在打包步骤中也失败了。

4) I tried various techniques in packing, nuspec files, the csproj file without success. 4)我在打包,nuspec文件,csproj文件中尝试了各种技术,但没有成功。

My YAML file looks like this:我的 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

' '

It always comes down to the same pathing problem with I use a nuspec file.我使用 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.

When I use a **/*.csproj for the pack, I get:当我对包使用 **/*.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.

Is it possible to publish a Xamarin project to a private nuget package feed in VSTS (DevOps)是否可以将 Xamarin 项目发布到私有 nuget package 源中的 VSTS(DevOps)

The answer is yes.答案是肯定的。 It depends on how many packages you want to generate.这取决于您要生成多少个包。

If you want to create one nuget package for 3 projects (iOS, Android, UWP), you should use the .nuspec file.如果要为 3 个项目(iOS、Android、UWP)创建一个 nuget package,则应使用.nuspec文件。

The path problem is because you are not set the correct path in the .nuspec file.路径问题是因为您没有在.nuspec文件中设置正确的路径。 The .nuspec file should be set at the folder that's one level below where the .sln file is. .nuspec文件应设置在.sln文件所在的下一级文件夹中。 The path to the dll is the relative path where the .nupsec file is stored. dll 的路径是存储.nupsec文件的相对路径。

So, the path should be like:所以,路径应该是这样的:

<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>

Check the document Create packages for Xamarin with Visual Studio 2015 for some details.查看文档 使用 Visual Studio 2015 为 Xamarin 创建包以了解一些详细信息。

If you want to create three nuget package for each platform, you can use the a **/*.csproj for the pack.如果要为每个平台创建三个 nuget package,则可以使用**/*.csproj为包。

The reason for your issue is that you need install the .NET core SDK before you build the project/solution:您的问题的原因是您需要在构建项目/解决方案之前安装 .NET 核心 SDK:

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

Hope this helps.希望这可以帮助。

So, my problem wasn't in my nuspec file;所以,我的问题不在我的 nuspec 文件中; the real problem comes down to using the vmImage: "macos-latest", which is required if you want to build an iOS project (iOS won't build under the agents 2019, or 2017, and you must use MSBuild (not VSBuild)真正的问题归结为使用 vmImage: "macos-latest",如果你想构建 iOS 项目,这是必需的(iOS 不会在代理 2019 或 2017 下构建,你必须使用 MSBuild(不是 VSBuild)

The macos-latest image has several issues (which I'll refer to as the iOS agent) macos-latest 镜像有几个问题(我将其称为 iOS 代理)

  1. The nuspec package for System.Threading.Task.Extensions (STTE) isn't included when you bring in another nuget package that has a dependency on it.当您引入另一个 nuget package 时,不包括用于 System.Threading.Task.Extensions (STTE) 的 nuspec package。 If the package is in the 'Standard .net 2.0 project", then the STTE package must be included in the standard project and the ios project; this only occurs in the ios agent. If the package is in the 'Standard .net 2.0 project", then the STTE package must be included in the standard project and the ios project; this only occurs in the ios agent.

  2. The variable I used for the solution path $(solution) did not expand to myproj.sln;我用于解决方案路径的变量 $(solution) 没有扩展到 myproj.sln; the logged showed the path as /$($solution) and the project did not build, no warning or errors that zero projects were built;日志将路径显示为 /$($solution) 并且项目没有构建,没有警告或错误表明构建了零个项目; the problem did not occur in any other agent type that I tested.在我测试的任何其他代理类型中都没有出现此问题。

  3. The ios agent's Xamarin sdk is woefully out of date and has to be set. ios 代理的 Xamarin sdk 严重过时,必须进行设置。

yaml required:需要 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)"

The technique used to figure this out was to split a Xamarin project into 4 separate projects and publish them as separate projects:用于解决此问题的技术是将 Xamarin 项目拆分为 4 个单独的项目,并将它们作为单独的项目发布:

  • .Net Standard 2.0 .Net 标准 2.0
  • UWP UWP
  • Android Android
  • iOS iOS

Every project but the iOS one worked using a VSBuild and the 2019 agent;除了 iOS 之外的每个项目都使用 VSBuild 和 2019 代理进行工作; it was then a process of elimination on the ios agent.然后是 ios 代理的消除过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为Android项目升级Xamarin.Forms NuGet包 - Can't upgrade Xamarin.Forms NuGet package for Android project 使用 HockeyApp Preseason nuget 包 OnPrepareOptionsMenu 注册 Xamarin Android 项目错误 - Registering Xamarin Android project with HockeyApp Preseason nuget package OnPrepareOptionsMenu error Xamarin添加NuGet包 - Xamarin adding NuGet package Xamarin NuGet软件包错误 - Xamarin NuGet package error 为什么不能将较早的xamarin表单版本作为nuget添加到Xamarin表单项目/ android程序包中? - Why can't I add a earlier xamarin forms version as a nuget into my Xamarin forms project/android package? 如何创建一个项目来为支持iOS,Android和UWP的Xamarin Forms创建Nuget包? - How does one create a project to create a Nuget package for Xamarin Forms supporting iOS, Android, and UWP? 样本Xamarin项目无法在VSTS中构建 - Sample Xamarin project fail build in VSTS 无法在Xamarin Form PCL项目中添加System.ServiceModel Nuget包 - Unable to Add System.ServiceModel Nuget Package in Xamarin Form PCL Project 干净的VS 2015 Enterprise + Xamarin安装:错误:项目的NuGet包还原失败 - clean VS 2015 Enterprise + Xamarin Install: error: NuGet Package restore failed for project VS2012与Xamarin 3,在将MvvmCross 3.1.1 nuget包添加到android项目时自由 - VS2012 with Xamarin 3, frezes when adding MvvmCross 3.1.1 nuget package to android project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM