我正在尝试在 Visual Studio 的 Xamarin.Android 项目中对我的 Android.Manifest 文件实施预构建转换 - 目的只是根据我是构建调试版本还是发布版本来更改我的应用程序的 bundleID。
我在我的解决方案中添加了一个新的 .netFramework 项目,引用了 Microsoft.Build,然后添加了一个名为 BuildTask 的新类,并在我的 Xamarin.Android 项目中引用了 DLL。
然后我打算在最底部的 Xamarin.Android 项目的 .csproj 文件中添加一个 UsingTask,就在结束标记的上方 - 我认为这是正确的。
在添加 UsingTask 之前,我想确保 Xamarin.Android 项目已构建,但不幸的是,我收到有关 Xamarin.Android 项目中缺少引用的错误,说我缺少对 System.Collections 的引用,但错误消失了第二个我删除了对我的新 BuildTask.DLL 的引用
我以前从未这样做过,所以我可能会陷入困境……如果有人有任何建议,将不胜感激。
这是我的 BuildTask 类以供参考:
using System;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System.Xml;
public class BuildTask : Task
{
private const string AndroidNamespace = "http://schemas.android.com/apk/res/android";
[Required]
public string PackageName { get; set; }
[Required]
public string ApplicationLabel { get; set; }
[Required]
public string ManifestFilename { get; set; }
public string Debuggable { get; set; }
public override bool Execute()
{
var xml = new XmlDocument();
xml.Load(ManifestFilename);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("android", AndroidNamespace);
if (xml.DocumentElement != null)
{
xml.DocumentElement.SetAttribute("package", PackageName);
var appNode = xml.DocumentElement.SelectSingleNode("/manifest/application", nsmgr);
if (appNode != null && appNode.Attributes != null)
{
var labelAttribute = appNode.Attributes["label", AndroidNamespace];
if (labelAttribute != null)
{
labelAttribute.Value = ApplicationLabel;
}
var debuggableAttribute = appNode.Attributes["debuggable", AndroidNamespace];
if (debuggableAttribute != null)
{
debuggableAttribute.Value = Debuggable;
}
xml.Save(ManifestFilename);
return true;
}
}
return false;
}
}
谢谢。
那是因为您将完整的 .NET Framework 引用到 Xamarin.Android 项目。这个完整的 .NET 框架与 Xamarin.Android 不兼容。您应该使用以下方法之一:
创建一个 Android 库项目。
创建一个可移植的类库项目。
创建共享项目。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句