public override void Run() { this.Init(); Dictionary <string, ClrApi> platformApis = this.LoadApis(); ClrApi mergedApi = this.MergeApis(platformApis); platformApis.Add(PluginInfo.PortablePlatformName, mergedApi); Assembly mergedAssembly = mergedApi.Assemblies.Single(); string xamarinPlatformId = XamarinPlatformIds.Get(PluginInfo.PortablePlatformName); string targetRelativePath = Path.Combine("build", xamarinPlatformId, mergedAssembly.Name + ".dll"); Log.Message(" " + targetRelativePath); Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(this.TargetOutputPath, targetRelativePath))); PortableAssemblyEmitter assemblyEmitter = new PortableAssemblyEmitter { Assembly = mergedAssembly, AssemblyFilePath = Path.Combine(this.TargetOutputPath, targetRelativePath), }; assemblyEmitter.Run(); Dictionary <string, Assembly> platformAssemblies = platformApis.ToDictionary(pa => pa.Key, pa => pa.Value.Assemblies.Single()); this.CopyAssemblies(platformAssemblies); this.GenerateNuspec(mergedAssembly, platformAssemblies); this.PackNugetPackage(); }
void CopyAssemblies(Dictionary <string, Assembly> platformAssemblies) { string configuration = (this.DebugConfiguration ? "debug" : "release"); string packageId = this.PluginInfo.Assembly.Name; string targetsFileName = packageId + ".targets"; string msbuildTargetName = "ResolvePluginReference_" + packageId; foreach (KeyValuePair <string, Assembly> platformAssembly in platformAssemblies) { string xamarinPlatformId = XamarinPlatformIds.Get(platformAssembly.Key); string targetsFilePath = Path.Combine("build", xamarinPlatformId, targetsFileName); Log.Message(" " + targetsFilePath); XNamespace ns = MsbuildXmlNamespace; XElement targetElement = new XElement( ns + "Target", new XAttribute("Name", msbuildTargetName), new XAttribute("BeforeTargets", "ResolveAssemblyReferences")); string[] platformSourcePaths; if (platformAssembly.Key == PluginInfo.WindowsPlatformName) { platformSourcePaths = new[] { @"windows\bin\x86", @"windows\bin\x64", @"windows\bin\ARM", }; } else { platformSourcePaths = new[] { Path.Combine(platformAssembly.Key, "bin"), }; } foreach (string platformSourcePath in platformSourcePaths) { string relativeAssemblyPath = Path.Combine( platformSourcePath, configuration, platformAssembly.Value.Name + ".dll"); string assemblyPath; if (platformAssembly.Key == PluginInfo.PortablePlatformName) { assemblyPath = Path.Combine( this.TargetOutputPath, "build", XamarinPlatformIds.Get(PluginInfo.PortablePlatformName), platformAssembly.Value.Name + ".dll"); } else { assemblyPath = this.FindIntermediateFile(relativeAssemblyPath); if (assemblyPath == null) { throw new InvalidOperationException( "Could not find platform assembly in intermediate path: " + Path.Combine(relativeAssemblyPath)); } } XElement itemGroupElement = new XElement(ns + "ItemGroup"); targetElement.Add(itemGroupElement); if (platformAssembly.Key == PluginInfo.WindowsPlatformName) { string platform = platformSourcePath.Replace("windows\\bin\\", String.Empty); itemGroupElement.Add(new XAttribute("Condition", " '$(Platform)' == '" + platform + "' ")); } foreach (string extension in new[] { ".dll", ".xml", ".pdb", ".dll.mdb", ".winmd", ".pri" }) { foreach (string sourcePath in Directory.GetFiles(Path.GetDirectoryName(assemblyPath), "*" + extension)) { string fileName = Path.GetFileName(sourcePath); if (fileName.StartsWith("temp.")) { continue; } bool isMainAssembly = String.Equals( fileName, this.PluginInfo.Assembly.Name + ".dll", StringComparison.OrdinalIgnoreCase); string targetRelativePath; if (platformAssembly.Key == PluginInfo.WindowsPlatformName) { string platform = platformSourcePath.Replace("windows\\bin\\", String.Empty); targetRelativePath = Path.Combine("build", xamarinPlatformId, platform, fileName); if (isMainAssembly) { itemGroupElement.Add(new XElement( ns + "Reference", new XAttribute("Include", this.PluginInfo.Assembly.Name), new XElement( ns + "HintPath", @"$(MSBuildThisFileDirectory)" + platform + @"\" + fileName) )); } else { itemGroupElement.Add(new XElement( ns + "None", new XAttribute( "Include", @"$(MSBuildThisFileDirectory)" + platform + @"\" + fileName), new XElement(ns + "DeploymentContent", true) )); } } else { targetRelativePath = Path.Combine("build", xamarinPlatformId, fileName); if (isMainAssembly) { itemGroupElement.Add(new XElement( ns + "Reference", new XAttribute("Include", this.PluginInfo.Assembly.Name), new XElement( ns + "HintPath", @"$(MSBuildThisFileDirectory)" + fileName) )); } else { itemGroupElement.Add(new XElement( ns + "None", new XAttribute( "Include", @"$(MSBuildThisFileDirectory)" + fileName), new XElement(ns + "DeploymentContent", true) )); } } if (File.Exists(sourcePath)) { Log.Message(" " + targetRelativePath); string targetFullPath = Path.Combine(this.TargetOutputPath, targetRelativePath); if (!Directory.Exists(Path.GetDirectoryName(targetFullPath))) { Directory.CreateDirectory(Path.GetDirectoryName(targetFullPath)); } // The portable assembly was already output in the correct location. if (platformAssembly.Key != PluginInfo.PortablePlatformName) { File.Copy(sourcePath, targetFullPath, true); } } } } } XElement propertyGroupElement = new XElement( ns + "PropertyGroup", new XElement( ns + "ResolveAssemblyReferencesDependsOn", "$(ResolveAssemblyReferencesDependsOn);" + msbuildTargetName)); XDocument targetsDocument = new XDocument(new XElement( ns + "Project", new XAttribute("ToolsVersion", "4.0"), targetElement, propertyGroupElement)); XmlWriterSettings xmlSettings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Document, Encoding = Encoding.UTF8, Indent = true }; using (XmlWriter writer = XmlWriter.Create( Path.Combine(this.TargetOutputPath, targetsFilePath), xmlSettings)) { targetsDocument.WriteTo(writer); } } }