构建期间快速获取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
XamarinIOSVersionproperty. It works exactly likeXamarinAndroidVersion—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:
- First, ensure your project has a
PackageReferencefor Xamarin.Forms (most projects do):<ItemGroup> <PackageReference Include="Xamarin.Forms" Version="5.0.0.2515" /> </ItemGroup> - 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.
- First, ensure your project has a
二、快速获取版本的其他方法
针对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
- macOS系统:
- Visual Studio IDE查看:
- Windows:进入
工具 > 选项 > Xamarin > iOS 设置,页面顶部就能看到版本号。 - macOS:进入
Visual Studio > 偏好设置 > Xamarin > iOS查看版本。
- Windows:进入
针对Xamarin.Forms
- 查看NuGet引用: 打开项目文件(.csproj),查看Xamarin.Forms对应的
PackageReference节点中的Version属性;或者在Visual Studio的NuGet包管理器中查看已安装的版本。 - 命令行查询:
该命令会列出当前项目中引用的Xamarin.Forms精确版本。dotnet list package Xamarin.Forms - 额外:运行时获取(如果需要): 如果你需要在代码中获取版本(而非仅构建时),可以用以下代码:
var formsVersion = typeof(Xamarin.Forms.Application).Assembly.GetName().Version;
内容的提问来源于stack exchange,提问作者awattar




