public ProjectItemGroup GetProjectItemGroup() { ProjectItemGroup projectItemGroup = new ProjectItemGroup(); List<ProjectItemGroupEmbeddedResource> embeddedResources = new List<ProjectItemGroupEmbeddedResource>(WinFormResXEntries); embeddedResources.AddRange(ResXEntries); embeddedResources.AddRange(OtherEmbeddedResources); projectItemGroup.EmbeddedResource = embeddedResources.ToArray(); List<ProjectItemGroupCompile> compileFiles = new List<ProjectItemGroupCompile>(); if(AssemblyInfoFileEntry != null) { compileFiles.Add(AssemblyInfoFileEntry); } compileFiles.AddRange(NormalCodeEntries); compileFiles.AddRange(WinFormCodeEntries); projectItemGroup.Compile = compileFiles.ToArray(); if (this.AppConfigFileEntry != null) { projectItemGroup.None = this.AppConfigFileEntry; } List<ProjectItemGroupPage> xamlPageList = new List<ProjectItemGroupPage>(XamlFileEntries.Count); for (int i = 0; i < XamlFileEntries.Count; i++) { if (XamlFileEntries[i] is ProjectItemGroupPage) { xamlPageList.Add((ProjectItemGroupPage)XamlFileEntries[i]); } else { projectItemGroup.ApplicationDefinition = (ProjectItemGroupApplicationDefinition)XamlFileEntries[i++]; } } projectItemGroup.Page = xamlPageList.ToArray(); projectItemGroup.Resource = OtherXamlResources.ToArray(); return projectItemGroup; }
protected ProjectItemGroup CreatePojectReferences(ModuleDefinition module, ProjectPropertyGroup basicProjectProperties) { ProjectItemGroup result = new ProjectItemGroup(); ICollection<AssemblyNameReference> dependingOnAssemblies = GetAssembliesDependingOn(module); result.Reference = new ProjectItemGroupReference[dependingOnAssemblies.Count]; string copiedReferencesSubfolder = basicProjectProperties.AssemblyName + "References"; string referencesPath = TargetPath.Remove(TargetPath.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar + copiedReferencesSubfolder; int assemblyReferenceIndex = 0; foreach (AssemblyNameReference reference in dependingOnAssemblies) { if (reference.Name == "mscorlib" || reference.Name == "Windows" && reference.Version.Equals(new Version(255, 255, 255, 255)) || reference.Name == "System.Runtime") { continue; } AssemblyName assemblyName = new AssemblyName(reference.Name, reference.FullName, reference.Version, reference.PublicKeyToken); string currentReferenceInitialLocation = this.currentAssemblyResolver.FindAssemblyPath(assemblyName, null); AssemblyDefinition referencedAssembly = this.currentAssemblyResolver.Resolve(reference, "", assembly.MainModule.GetModuleArchitecture()); #if NET35 if (!currentReferenceInitialLocation.IsNullOrWhiteSpace()) #else if (!string.IsNullOrWhiteSpace(currentReferenceInitialLocation)) #endif { result.Reference[assemblyReferenceIndex] = new ProjectItemGroupReference(); if (IsInReferenceAssemblies(referencedAssembly)) { //TODO: Consider doing additional check, to see if the assembly is resolved because it was pointed by the used/already in the tree // In this case, it might be better to copy it. result.Reference[assemblyReferenceIndex].Include = reference.Name; } else // Copy the referenced assembly { if (!Directory.Exists(referencesPath)) { Directory.CreateDirectory(referencesPath); } string currentReferenceFileName = Path.GetFileName(currentReferenceInitialLocation); string currentReferenceFinalLocation = Path.Combine(referencesPath, currentReferenceFileName); File.Copy(currentReferenceInitialLocation, currentReferenceFinalLocation, true); // set to normal for testing purposes- to allow the test project to delete the coppied file between test runs File.SetAttributes(currentReferenceFinalLocation, FileAttributes.Normal); string relativePath = Path.Combine(".", copiedReferencesSubfolder); relativePath = Path.Combine(relativePath, currentReferenceFileName); result.Reference[assemblyReferenceIndex].Include = Path.GetFileNameWithoutExtension(currentReferenceFinalLocation); result.Reference[assemblyReferenceIndex].Item = relativePath; } } assemblyReferenceIndex++; } ICollection<ModuleReference> dependingOnModules = GetModulesDependingOn(module); result.AddModules = new ProjectItemGroupAddModules[dependingOnModules.Count * 2]; int moduleReferenceIndex = 0; foreach (ModuleReference moduleRef in dependingOnModules) { result.AddModules[moduleReferenceIndex] = new ProjectItemGroupAddModules(); result.AddModules[moduleReferenceIndex].Include = @"bin\Debug\" + Utilities.GetNetmoduleName(moduleRef) + ".netmodule"; result.AddModules[moduleReferenceIndex].Condition = " '$(Configuration)' == 'Debug' "; moduleReferenceIndex++; result.AddModules[moduleReferenceIndex] = new ProjectItemGroupAddModules(); result.AddModules[moduleReferenceIndex].Include = @"bin\Release\" + Utilities.GetNetmoduleName(moduleRef) + ".netmodule"; result.AddModules[moduleReferenceIndex].Condition = " '$(Configuration)' == 'Release' "; moduleReferenceIndex++; } return result; }
protected override object[] GetProjectItems(ModuleDefinition module, ProjectPropertyGroup basicProjectProperties) { object[] items = null; bool isVisualBasic = this.language is VisualBasic; if (this.projectType == WinRTProjectType.Component || this.projectType == WinRTProjectType.ComponentForWindows) { items = isVisualBasic ? new object[15] : new object[14]; int i = 0; items[i++] = this.GenerateCommonPropsProjectImportProperty(); items[i++] = basicProjectProperties; object[] configurations = this.GetConfigurations(basicProjectProperties); for (int j = 0; j < configurations.Length; j++, i++) { items[j + 2] = configurations[j]; } items[i++] = this.CreatePojectReferences(module, basicProjectProperties); items[i++] = this.fileGenContext.GetProjectItemGroup(); items[i++] = this.GetVisualStudioVersionPropertyGroup(); if (isVisualBasic) { items[i++] = this.GetCompileOptions(); } items[i++] = this.GenerateLanguageTargetsProjectImportProperty(); } else if (this.projectType == WinRTProjectType.ComponentForUniversal) { items = new object[8]; items[0] = this.GenerateCommonPropsProjectImportProperty(); items[1] = basicProjectProperties; object[] configurations = this.GetConfigurations(basicProjectProperties); for (int i = 0; i < configurations.Length; i++) { items[i + 2] = configurations[i]; } items[4] = this.CreatePojectReferences(module, basicProjectProperties); items[5] = new ProjectItemGroup() { TargetPlatform = new ProjectItemGroupTargetPlatform[] { new ProjectItemGroupTargetPlatform() { Include = "WindowsPhoneApp, Version=8.1" }, new ProjectItemGroupTargetPlatform() { Include = "Windows, Version=8.1" } } }; items[6] = this.fileGenContext.GetProjectItemGroup(); items[7] = this.GenerateLanguageTargetsProjectImportProperty(); } else if (this.projectType == WinRTProjectType.ComponentForWindowsPhone) { items = isVisualBasic ? new object[14] : new object[13]; int i = 0; items[i++] = this.GenerateCommonPropsProjectImportProperty(); items[i++] = basicProjectProperties; object[] configurations = this.GetConfigurations(basicProjectProperties); for (int j = 0; j < configurations.Length; j++, i++) { items[j + 2] = configurations[j]; } items[i++] = this.CreatePojectReferences(module, basicProjectProperties); items[i++] = this.fileGenContext.GetProjectItemGroup(); items[i++] = this.GetVisualStudioVersionPropertyGroup(); items[i++] = new ProjectPropertyGroup() { Condition = " '$(TargetPlatformIdentifier)' == '' ", TargetPlatformIdentifier = "WindowsPhoneApp" }; if (isVisualBasic) { items[i++] = this.GetCompileOptions(); } items[i++] = this.GenerateLanguageTargetsProjectImportProperty(); } return items; }
protected override object[] GetProjectItems(ModuleDefinition module, ProjectPropertyGroup basicProjectProperties) { bool shouldAddVisualBasicItems = this.language is IVisualBasic && this.projectType != WinRTProjectType.ComponentForUniversal; object[] items = new object[GetNumberOfProjectItems(shouldAddVisualBasicItems)]; int currentItem = 0; items[currentItem++] = this.GenerateCommonPropsProjectImportProperty(); items[currentItem++] = basicProjectProperties; object[] configurations = this.GetConfigurations(basicProjectProperties); for (int j = 0; j < configurations.Length; j++) { items[currentItem++] = configurations[j]; } items[currentItem++] = this.CreatePojectReferences(module, basicProjectProperties); if (this.projectType == WinRTProjectType.ComponentForUniversal) { items[currentItem++] = new ProjectItemGroup() { TargetPlatform = new ProjectItemGroupTargetPlatform[] { new ProjectItemGroupTargetPlatform() { Include = "WindowsPhoneApp, Version=8.1" }, new ProjectItemGroupTargetPlatform() { Include = "Windows, Version=8.1" } } }; } items[currentItem++] = this.fileGenContext.GetProjectItemGroup(); if (this.projectType != WinRTProjectType.ComponentForUniversal) { items[currentItem++] = this.GetVisualStudioVersionPropertyGroup(); } if (this.projectType == WinRTProjectType.ComponentForWindowsPhone) { items[currentItem++] = new ProjectPropertyGroup() { Condition = " '$(TargetPlatformIdentifier)' == '' ", TargetPlatformIdentifier = "WindowsPhoneApp" }; } if (shouldAddVisualBasicItems) { items[currentItem++] = this.GetCompileOptions(); } items[currentItem++] = this.GenerateLanguageTargetsProjectImportProperty(); return items; }