【发布时间】:2017-11-24 12:09:26
【问题描述】:
我正在尝试在 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;
}
}
谢谢。
【问题讨论】:
标签: android visual-studio msbuild transformation xdt