Visual Studio 내에서 Xamarin.Android 프로젝트 내 Android.Manifest 파일에 대한 사전 빌드 변환을 구현하려고합니다. 목적은 단순히 내 응용 프로그램의 번들 ID를 변경하는 것입니다. 내가 디버그 나 릴리즈 버전을 빌드하는지 여부.Visual Studio (Xamarin)의 구성 변환
내 솔루션에 새로운 .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;
}
}
감사합니다.