You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

构建期间快速获取Xamarin.iOS、Xamarin.Forms版本的方法问询

获取Xamarin.iOS和Xamarin.Forms版本的方法

Great question! Let’s break this down clearly—covering both the MSBuild property equivalents you’re asking for (since you referenced XamarinAndroidVersion) and quick ways to grab these versions during builds or development.

一、MSBuild构建属性(对应XamarinAndroidVersion的等效项)

These are the properties you can use directly in MSBuild scripts, project files, or build commands to access the versions during the build process:

  • Xamarin.iOS: Use the XamarinIOSVersion property. It works exactly like XamarinAndroidVersion—you can reference it in your project file or custom MSBuild targets. For example:

    <Target Name="LogiOSVersion" BeforeTargets="Build">
      <Message Text="Current Xamarin.iOS version being used: $(XamarinIOSVersion)" Importance="High" />
    </Target>
    
  • Xamarin.Forms: There’s no global MSBuild property equivalent to the ones above, since Forms is distributed as a NuGet package rather than a platform SDK. Instead, you can retrieve the version from your project’s NuGet reference:

    1. First, ensure your project has a PackageReference for Xamarin.Forms (most projects do):
      <ItemGroup>
        <PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" />
      </ItemGroup>
      
    2. Add a custom MSBuild target to extract the version from the referenced assembly:
      <Target Name="LogFormsVersion" BeforeTargets="Build">
        <GetAssemblyIdentity AssemblyFiles="$(OutputPath)\Xamarin.Forms.Core.dll">
          <Output TaskParameter="Assemblies" ItemName="FormsAssembly" />
        </GetAssemblyIdentity>
        <Message Text="Xamarin.Forms version in use: %(FormsAssembly.Version)" Importance="High" />
      </Target>
      

    Alternatively, if you just need to check the version during a command-line build, you can use NuGet’s built-in commands to list the installed package version.

二、快速获取版本的其他方法

针对Xamarin.iOS

  • 命令行(最快方式):
    • macOS系统:
      /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --version
      
    • Windows系统:
      "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\mtouch.exe" --version
      
    运行后会直接输出你机器上安装的Xamarin.iOS精确版本。
  • Visual Studio IDE查看:
    • Windows:进入工具 > 选项 > Xamarin > iOS 设置,页面顶部就能看到版本号。
    • macOS:进入Visual Studio > 偏好设置 > Xamarin > iOS查看版本。

针对Xamarin.Forms

  • 查看NuGet引用: 打开项目文件(.csproj),查看Xamarin.Forms对应的PackageReference节点中的Version属性;或者在Visual Studio的NuGet包管理器中查看已安装的版本。
  • 命令行查询:
    dotnet list package Xamarin.Forms
    
    该命令会列出当前项目中引用的Xamarin.Forms精确版本。
  • 额外:运行时获取(如果需要): 如果你需要在代码中获取版本(而非仅构建时),可以用以下代码:
    var formsVersion = typeof(Xamarin.Forms.Application).Assembly.GetName().Version;
    

内容的提问来源于stack exchange,提问作者awattar

火山引擎 最新活动