private void AddProjectReference(ProjectReference projectRef) { Dependency dependency = new Dependency(); dependency.artifactId = projectRef.Name; dependency.groupId = !string.IsNullOrEmpty(groupId) ? groupId : projectRef.Name; dependency.version = string.IsNullOrEmpty(version) ? "1.0-SNAPSHOT" : version; dependency.type = "dotnet-library"; if (projectRef.ProjectReferenceDigest != null && !string.IsNullOrEmpty(projectRef.ProjectReferenceDigest.OutputType)) { string type = projectRef.ProjectReferenceDigest.OutputType.ToLower(); if (npandayTypeMap.ContainsKey(type)) type = npandayTypeMap[type]; dependency.type = type; } if (projectRef.RoleType != null) { string targetFramework = projectDigest.TargetFramework; // TODO: same hack as above - the Azure project doesn't need to target a framework, and instead we should support different ones (See also azure-maven-plugin roleproperties generation) if (string.IsNullOrEmpty(targetFramework)) targetFramework = "4.0"; if (!projectRef.ProjectReferenceDigest.TargetFramework.Equals(targetFramework)) { log.WarnFormat("Project reference '{0}' targets a different framework version ({1}) to the Azure project ({2}), and may not succeed when uploaded to Azure.", projectRef.Name, projectRef.ProjectReferenceDigest.TargetFramework, targetFramework); } switch (projectRef.RoleType) { case "Web": dependency.type = "msdeploy-package"; break; case "Worker": dependency.type = "dotnet-application"; break; default: log.Warn("Unknown role type '" + projectRef.RoleType + "' - treating as a dotnet-library"); break; } } AddDependency(dependency); }
public ProjectDigest DigestProject(Dictionary<string, object> projectMap, DependencySearchConfiguration depSearchConfig) { Project project = (Project)projectMap["Project"]; log.DebugFormat("Digesting project {0}", project.FullFileName); if (!projectMap.ContainsKey("ProjectType")) { if (project.FullFileName.ToUpper().EndsWith(".CSPROJ")) { projectMap.Add("ProjectType",VisualStudioProjectTypeEnum.Windows__CSharp); } else if (project.FullFileName.ToUpper().EndsWith(".VBPROJ")) { projectMap.Add("ProjectType", VisualStudioProjectTypeEnum.Windows__VbDotNet); } } ProjectDigest projectDigest = new ProjectDigest(); string projectBasePath = Path.GetDirectoryName(project.FullFileName); projectDigest.ProjectType = (VisualStudioProjectTypeEnum)projectMap["ProjectType"]; projectDigest.FullFileName = project.FullFileName; projectDigest.FullDirectoryName = Path.GetDirectoryName(project.FullFileName); if (projectMap.ContainsKey("Configuration")) projectDigest.Configuration = projectMap["Configuration"].ToString(); projectDigest.DependencySearchConfig = depSearchConfig; FileInfo existingPomFile = new FileInfo(Path.Combine(projectDigest.FullDirectoryName, "pom.xml")); if (existingPomFile.Exists) { projectDigest.ExistingPom = PomHelperUtility.ReadPomAsModel(existingPomFile); } if ((projectDigest.ProjectType & VisualStudioProjectTypeEnum.Windows__CSharp) == VisualStudioProjectTypeEnum.Windows__CSharp) { projectDigest.Language = "csharp"; } else if ((projectDigest.ProjectType & VisualStudioProjectTypeEnum.Windows__VbDotNet) == VisualStudioProjectTypeEnum.Windows__VbDotNet) { projectDigest.Language = "vb"; } List<Reference> references = new List<Reference>(); List<ProjectReference> projectReferences = new List<ProjectReference>(); if (projectMap.ContainsKey("InterProjectReferences") && projectMap["InterProjectReferences"] != null && projectMap["InterProjectReferences"] is Microsoft.Build.BuildEngine.Project[] ) { Microsoft.Build.BuildEngine.Project[] interProjectReferences = (Microsoft.Build.BuildEngine.Project[])projectMap["InterProjectReferences"]; foreach (Microsoft.Build.BuildEngine.Project p in interProjectReferences) { ProjectReference prjRef = new ProjectReference(projectBasePath); prjRef.ProjectPath = p.FullFileName; prjRef.Name = GetProjectAssemblyName(Path.GetFullPath(prjRef.ProjectFullPath)); projectReferences.Add(prjRef); } } List<Compile> compiles = new List<Compile>(); List<None> nones = new List<None>(); List<WebReferenceUrl> webReferenceUrls = new List<WebReferenceUrl>(); List<Content> contents = new List<Content>(); List<WebReferences> webReferencesList = new List<WebReferences>(); List<EmbeddedResource> embeddedResources = new List<EmbeddedResource>(); List<BootstrapperPackage> bootstrapperPackages = new List<BootstrapperPackage>(); List<Folder> folders = new List<Folder>(); List<string> globalNamespaceImports = new List<string>(); List<ComReference> comReferenceList = new List<ComReference>(); DigestBuildProperties(project, projectDigest); DigestBuildItems(project, projectDigest, projectBasePath, projectReferences, references, compiles, nones, webReferenceUrls, contents, folders, webReferencesList, embeddedResources, bootstrapperPackages, globalNamespaceImports, comReferenceList); DigestImports(project); projectDigest.ProjectReferences = projectReferences.ToArray(); projectDigest.References = references.ToArray(); projectDigest.Compiles = compiles.ToArray(); projectDigest.Contents = contents.ToArray(); projectDigest.Nones = nones.ToArray(); projectDigest.WebReferenceUrls = webReferenceUrls.ToArray(); projectDigest.WebReferences = webReferencesList.ToArray(); projectDigest.EmbeddedResources = embeddedResources.ToArray(); projectDigest.BootstrapperPackages = bootstrapperPackages.ToArray(); projectDigest.Folders = folders.ToArray(); projectDigest.GlobalNamespaceImports = globalNamespaceImports.ToArray(); projectDigest.ComReferenceList = comReferenceList.ToArray(); return projectDigest; }
public ProjectDigest DigestProject(Dictionary<string, object> projectMap, DependencySearchConfiguration depSearchConfig) { ProjectDigest projectDigest = new ProjectDigest(); projectDigest.ProjectType = (VisualStudioProjectTypeEnum)projectMap["ProjectType"]; projectDigest.FullFileName = projectMap["ProjectFullPath"].ToString(); projectDigest.FullDirectoryName = projectDigest.FullFileName; if (projectMap.ContainsKey("TargetFramework")) projectDigest.TargetFramework = projectMap["TargetFramework"].ToString(); if (projectMap.ContainsKey("Configuration")) projectDigest.Configuration = projectMap["Configuration"].ToString(); projectDigest.DependencySearchConfig = depSearchConfig; FileInfo existingPomFile = new FileInfo(Path.Combine(projectDigest.FullDirectoryName, "pom.xml")); if(existingPomFile.Exists) { projectDigest.ExistingPom = PomHelperUtility.ReadPomAsModel(existingPomFile); } // get Assembly name if (projectMap.ContainsKey("Release.AspNetCompiler.VirtualPath")) { projectDigest.Name = projectMap["Release.AspNetCompiler.VirtualPath"].ToString() .Replace(@"/", "") .Replace(@"\\", ""); } else if (projectMap.ContainsKey("Debug.AspNetCompiler.VirtualPath")) { projectDigest.Name = projectMap["Debug.AspNetCompiler.VirtualPath"].ToString() .Replace(@"/", "") .Replace(@"\\", ""); } else if(projectMap.ContainsKey("ProjectFullPath")) { projectDigest.Name = new DirectoryInfo(projectMap["ProjectFullPath"].ToString()).Name; } // InterProjectReferences List<ProjectReference> prjRefList = new List<ProjectReference>(); if (projectMap.ContainsKey("InterProjectReferences")) { foreach (Project var in (Project[])projectMap["InterProjectReferences"]) { ProjectReference prjRef = new ProjectReference(projectMap["ProjectFullPath"].ToString()); prjRef.Name = GetProjectAssemblyName(Path.GetFullPath(var.FullFileName)); prjRef.ProjectPath = Path.GetFullPath(var.FullFileName); prjRefList.Add(prjRef); } } projectDigest.ProjectReferences = prjRefList.ToArray(); //WebConfigAssemblies List<Reference> webConfigRefList = new List<Reference>(); //if (projectMap.ContainsKey("WebConfigAssemblies")) //{ // foreach (string var in (string[]) projectMap["WebConfigAssemblies"]) // { // Reference reference = new Reference(projectMap["ProjectFullPath"].ToString(), gac); // reference.AssemblyInfo = var; // webConfigRefList.Add(reference); // } //} //WebReferenceURL //if (projectMap.ContainsKey("WebReferencesUrl")) //{ // List<WebReferenceUrl> webReferenceUrls = new List<WebReferenceUrl>(); // if (projectDigest.WebReferenceUrls != null && projectDigest.WebReferenceUrls.Length > 0) // { // webReferenceUrls.AddRange(projectDigest.WebReferenceUrls); // } // foreach (WebReferenceUrl webReferenceUrl in (WebReferenceUrl[])projectMap["WebReferencesUrl"]) // { // if (webReferenceUrl != null && !string.IsNullOrEmpty(webReferenceUrl.RelPath) && !string.IsNullOrEmpty(webReferenceUrl.UpdateFromURL)) // webReferenceUrls.Add(webReferenceUrl); // } // projectDigest.WebReferenceUrls = webReferenceUrls.ToArray(); //} //BinAssemblies List<Reference> binRefList = new List<Reference>(); //if (projectMap.ContainsKey("BinAssemblies")) //{ // foreach (string var in (string[])projectMap["BinAssemblies"]) // { // // exclude if its already in the webconfig // Reference reference = new Reference(projectMap["ProjectFullPath"].ToString(), gac); // reference.HintPath = var; // // check if its not in project-reference or webconfig-assemblies references // if (!ReferenceInReferenceList(reference, webConfigRefList) && !ReferenceInProjectReferenceList(reference, prjRefList)) // { // binRefList.Add(reference); // } // } //} // combine both web and bin assemblies List<Reference> referenceList = new List<Reference>(); //referenceList.AddRange(webConfigRefList); //referenceList.AddRange(binRefList); projectDigest.References = referenceList.ToArray(); return projectDigest; }
private static void DigestBuildItems(Project project, ProjectDigest projectDigest, string projectBasePath, ICollection<ProjectReference> projectReferences, ICollection<Reference> references, ICollection<Compile> compiles, ICollection<None> nones, ICollection<WebReferenceUrl> webReferenceUrls, ICollection<Content> contents, ICollection<Folder> folders, ICollection<WebReferences> webReferencesList, ICollection<EmbeddedResource> embeddedResources, ICollection<BootstrapperPackage> bootstrapperPackages, ICollection<string> globalNamespaceImports, IList<ComReference> comReferenceList) { string targetFramework = projectDigest.TargetFramework != null ? projectDigest.TargetFramework.Substring(0,3) : "2.0"; RspUtility rsp = new RspUtility(); foreach (BuildItemGroup buildItemGroup in project.ItemGroups) { foreach (BuildItem buildItem in buildItemGroup) { if (!buildItem.IsImported) { switch (buildItem.Name) { case "ProjectReference": ProjectReference prjRef = new ProjectReference(projectBasePath); prjRef.ProjectPath = buildItem.Include; prjRef.Name = GetProjectAssemblyName(Path.GetFullPath(prjRef.ProjectFullPath)); prjRef.RoleType = buildItem.GetMetadata("RoleType"); projectReferences.Add(prjRef); break; case "Reference": // TODO: significant refactoring needed here - it should be calling the same resolution code that is in // AbstractPomConverter to find the right artifact based on the simple name Reference reference = new Reference(projectBasePath); //set processorArchitecture property to platform, it will be used by GacUtility in // order to resolve artifact to right processor architecture if (!string.IsNullOrEmpty(projectDigest.Platform)) { reference.ProcessorArchitecture = projectDigest.Platform; } string hintPath = buildItem.GetMetadata("HintPath"); if (!string.IsNullOrEmpty(hintPath)) { string fullHint = Path.Combine(projectBasePath, hintPath); if(File.Exists(fullHint)) reference.HintPath = Path.GetFullPath(fullHint); else reference.HintPath = fullHint; SetReferenceFromFile(new FileInfo(fullHint), reference); } if ((string.IsNullOrEmpty(reference.HintPath) || !(new FileInfo(reference.HintPath).Exists)) && !rsp.IsRspIncluded(buildItem.Include, projectDigest.Language)) { if (buildItem.Include.Contains(",")) { // complete name reference.SetAssemblyInfoValues(buildItem.Include); } else if (projectDigest.DependencySearchConfig.SearchGac && projectDigest.TargetFrameworkIdentifier != "Silverlight") { // simple name needs to be resolved List<string> refs = GacUtility.GetInstance().GetAssemblyInfo(buildItem.Include, null, null); if (refs.Count == 0) { log.Warn("Unable to find reference '" + buildItem.Include + "' in " + string.Join("; ", refs.ToArray())); } else if (refs.Count > 1) { string best = null; string bestFramework = "0.0"; foreach (string s in refs) { try { Assembly a = Assembly.ReflectionOnlyLoad(s); string framework = a.ImageRuntimeVersion.Substring(1, 3); if (framework.CompareTo(targetFramework) <= 0 && framework.CompareTo(bestFramework) > 0) { best = s; bestFramework = framework; } } catch (Exception e) { // skip this assembly log.Error("An error occurred loading assembly '" + s + "' - check that your PATH to gacutil matches your runtime environment: " + e.Message); } } reference.SetAssemblyInfoValues(best); } else { reference.SetAssemblyInfoValues(refs[0]); } } else { reference.Name = buildItem.Include; } } if ("NUnit.Framework".Equals(reference.Name, StringComparison.OrdinalIgnoreCase)) { reference.Name = "NUnit.Framework"; projectDigest.UnitTest = true; } if (!string.IsNullOrEmpty(reference.Name)) { references.Add(reference); } break; case "Compile": Compile compile = new Compile(projectBasePath); compile.IncludePath = buildItem.Include; compile.AutoGen = buildItem.GetMetadata("AutoGen"); compile.DesignTimeSharedInput = buildItem.GetMetadata("DesignTimeSharedInput"); compile.DependentUpon = buildItem.GetMetadata("DependentUpon"); compile.DesignTime = buildItem.GetMetadata("DesignTime"); compile.SubType = buildItem.GetMetadata("SubType"); compiles.Add(compile); break; case "None": None none = new None(projectBasePath); none.IncludePath = buildItem.Include; none.Link = buildItem.GetMetadata("Link"); none.Generator = buildItem.GetMetadata("Generator"); none.LastGenOutput = buildItem.GetMetadata("LastGenOutput"); none.DependentUpon = buildItem.GetMetadata("DependentUpon"); nones.Add(none); //add included web reference when reimporting if (buildItem.Include.Contains(".wsdl")) { string path = Path.GetDirectoryName(buildItem.Include) + "\\"; WebReferenceUrl webUrl = new WebReferenceUrl(); webUrl.UrlBehavior = "Dynamic"; webUrl.RelPath = path; if (!webRefExists(webUrl, webReferenceUrls)) { webReferenceUrls.Add(webUrl); } } break; case "WebReferenceUrl": WebReferenceUrl web = new WebReferenceUrl(); web.UrlBehavior = buildItem.GetMetadata("UrlBehavior"); web.RelPath = buildItem.GetMetadata("RelPath"); web.UpdateFromURL = buildItem.GetMetadata("UpdateFromURL"); web.ServiceLocationURL = buildItem.GetMetadata("ServiceLocationURL"); web.CachedDynamicPropName = buildItem.GetMetadata("CachedDynamicPropName"); web.CachedAppSettingsObjectName = buildItem.GetMetadata("CachedAppSettingsObjectName"); web.CachedSettingsPropName = buildItem.GetMetadata("CachedSettingsPropName"); if (!webRefExists(web, webReferenceUrls)) { webReferenceUrls.Add(web); } break; case "COMReference": ComReference comRef = new ComReference(); comRef.Include = buildItem.Include; comRef.Guid = buildItem.GetMetadata("Guid"); comRef.VersionMajor = buildItem.GetMetadata("VersionMajor"); comRef.VersionMinor = buildItem.GetMetadata("VersionMinor"); comRef.Lcid = buildItem.GetMetadata("Lcid"); comRef.Isolated = buildItem.GetMetadata("Isolated"); comRef.WrapperTool = buildItem.GetMetadata("WrapperTool"); comReferenceList.Add(comRef); break; case "Content": Content content = new Content(projectBasePath); content.IncludePath = buildItem.Include; contents.Add(content); //add web reference in <includes> tag of compile-plugin if (content.IncludePath.Contains("Web References")) { Compile compileWebRef = new Compile(projectBasePath); compileWebRef.IncludePath = buildItem.Include; compiles.Add(compileWebRef); } break; case "Folder": Folder folder = new Folder(projectBasePath); folder.IncludePath = buildItem.Include; folders.Add(folder); break; case "WebReferences": WebReferences webReferences = new WebReferences(projectBasePath); webReferences.IncludePath = buildItem.Include; webReferencesList.Add(webReferences); break; case "EmbeddedResource": EmbeddedResource embeddedResource = new EmbeddedResource(projectBasePath); embeddedResource.IncludePath = buildItem.Include; embeddedResource.DependentUpon = buildItem.GetMetadata("DependentUpon"); embeddedResource.SubType = buildItem.GetMetadata("SubType"); embeddedResource.Generator = buildItem.GetMetadata("Generator"); embeddedResource.LastGenOutput = buildItem.GetMetadata("LastGenOutput"); embeddedResource.WithCulture = buildItem.GetMetadata("WithCulture"); if (string.IsNullOrEmpty(embeddedResource.WithCulture)) { embeddedResource.WithCulture = MSBuildUtils.DetermineResourceCulture(buildItem.Include); } embeddedResources.Add(embeddedResource); break; case "BootstrapperPackage": BootstrapperPackage bootstrapperPackage = new BootstrapperPackage(projectBasePath); bootstrapperPackage.IncludePath = buildItem.Include; bootstrapperPackage.Visible = buildItem.GetMetadata("Visible"); bootstrapperPackage.ProductName = buildItem.GetMetadata("ProductName"); bootstrapperPackage.Install = buildItem.GetMetadata("Install"); bootstrapperPackages.Add(bootstrapperPackage); break; case "Import": globalNamespaceImports.Add(buildItem.Include); break; case "BaseApplicationManifest": projectDigest.BaseApplicationManifest = buildItem.Include; break; default: log.Debug("Unhandled ItemGroup: " + buildItem.Name); break; } } } } }
protected void AddInterProjectDependency(ProjectReference projectRef) { AddDependency(CreateInterProjectDependency(projectRef.Name, projectRef.ProjectReferenceDigest)); }