private string GetAssemblyPathFromAssemblyFolders(MsBuildProjectLoader msBuildLoader, BuildItem item) { string spec = GetReferenceDllName(item); string[] assemblyFoldersPaths = FrameworkHelper.GetFrameworkPaths(msBuildLoader.TargetFramework); assemblyFoldersPaths = ReversePaths(assemblyFoldersPaths); string path = FrameworkHelper.GetAssemblyPath(spec, assemblyFoldersPaths); if (File.Exists(path)) { return path; } assemblyFoldersPaths = FrameworkHelper.GetAssemblyFoldersPaths(msBuildLoader.TargetFramework); path = FrameworkHelper.GetAssemblyPath(spec, assemblyFoldersPaths); if (File.Exists(path)) { return path; } try { Assembly assembly = Assembly.Load(item.FinalItemSpec); if (assembly != null) { return assembly.Location; } } catch { } try { Assembly assembly = Assembly.LoadWithPartialName(item.FinalItemSpec); if (assembly != null) { return assembly.Location; } } catch { } return string.Empty; }
private void LoadFiles(ProjectElement result, MsBuildProjectLoader msBuildLoader, string projectDir) { IEnumerable<BuildItem> compileItems = msBuildLoader.GetProjectItems(STR_Compile); LoadBuildItems(result, projectDir, compileItems); IEnumerable<BuildItem> appDefinitionItems = msBuildLoader.GetProjectItems(STR_ApplicationDefinition); LoadBuildItems(result, projectDir, appDefinitionItems); IEnumerable<BuildItem> pageItems = msBuildLoader.GetProjectItems(STR_Page); LoadBuildItems(result, projectDir, pageItems); IEnumerable<BuildItem> contentItems = msBuildLoader.GetProjectItems(STR_Content); LoadBuildItems(result, projectDir, contentItems); }
// protected methods... protected override ProjectElement LoadProject(ProjectInfo info, Hashtable projects, string configuration, string platform) { if (info.Kind == STR_SolutionFolder) { return null; } if (info.Kind == ProjectTypeGuidConstants.WebSite) { return LoadWebSiteProject(info, projects); } string projectDir = Path.GetDirectoryName(info.FilePath); ProjectElement result = CreateProjectElement(info); MsBuildProjectLoader msBuildLoader = new MsBuildProjectLoader(info.FilePath); result.OptionStrict = msBuildLoader.OptionStrict; result.SetRootNamespace(msBuildLoader.RootNamespace); result.SetAssemblyName(msBuildLoader.AssemblyName); result.SetTargetFramework(msBuildLoader.TargetFramework); LoadProjectTypeGuids(result, msBuildLoader); LoadNotImportStdLibOption(result, msBuildLoader); LoadProjectDefines(result, msBuildLoader, configuration, platform); LoadReferences(result, msBuildLoader, projectDir); LoadProjectReferences(result, msBuildLoader, projects); LoadImportedNamespaces(result, msBuildLoader); LoadFiles(result, msBuildLoader, projectDir); return result; }
private void LoadProjectReferences(ProjectElement result, MsBuildProjectLoader msBuildLoader, Hashtable projects) { IEnumerable<BuildItem> projectReferenceItems = msBuildLoader.GetProjectItems(STR_ProjectReference); foreach (BuildItem item in projectReferenceItems) { string prj = item.GetMetadata(STR_Project); ProjectInfo projectInfo = projects[prj] as ProjectInfo; if (projectInfo == null) { continue; } AssemblyReference projectRef = new AssemblyReference(String.Empty); projectRef.SetSourceProjectFullName(projectInfo.FilePath); result.AddReference(projectRef); } }
private void LoadImportedNamespaces(ProjectElement result, MsBuildProjectLoader msBuildLoader) { IEnumerable<BuildItem> importItems = msBuildLoader.GetProjectItems(STR_Import); foreach (BuildItem item in importItems) { result.AddImportedNamespace(item.FinalItemSpec); } }
private void LoadNotImportStdLibOption(ProjectElement result, MsBuildProjectLoader msBuildLoader) { if (result == null) { return; } if (!result.ContainsProjectTypeGuid(ProjectTypeGuidConstants.WindowsCSharp)) { string extension = Path.GetExtension(result.FilePath); if (extension != ".csproj") { return; } } result.NotImportStdLib = msBuildLoader.NotImportStdLib; if (msBuildLoader.NotImportStdLib) { result.NeedLoadCoreAssembly = false; } }
private void LoadReferences(ProjectElement result, MsBuildProjectLoader msBuildLoader, string projectDir) { IEnumerable<BuildItem> referenceItems = msBuildLoader.GetProjectItems(STR_Reference); foreach (BuildItem item in referenceItems) { string aliases = item.GetEvaluatedMetadata(STR_Aliases); AssemblyReference reference = AddReference(result, msBuildLoader, item, projectDir, aliases); if (reference == null) { continue; } } }
private void LoadProjectTypeGuids(ProjectElement result, MsBuildProjectLoader msBuildLoader) { string projectTypeGuids = msBuildLoader.GetProperty(STR_ProjectTypeGuids); if (string.IsNullOrEmpty(projectTypeGuids)) { return; } result.SetProjectTypeGuids(projectTypeGuids); }
private void LoadProjectDefines(ProjectElement result, MsBuildProjectLoader msBuildLoader, string configuration, string platform) { string definesStr = string.Empty; if (string.IsNullOrEmpty(configuration) || string.IsNullOrEmpty(platform)) { definesStr = msBuildLoader.GetProperty(STR_DefineConstants); } else { definesStr = msBuildLoader.GetPropertyWithCondition(string.Format(" '$(Configuration)|$(Platform)' == '{0}|{1}' ", configuration, platform), STR_DefineConstants); } if (string.IsNullOrEmpty(definesStr)) { return; } result.SetDefines(definesStr.Split(CHAR_SemiColon)); }
private AssemblyReference AddReference(ProjectElement project, MsBuildProjectLoader msBuildLoader, BuildItem item, string projectDir, string aliases) { AssemblyReference reference = null; string dllName = GetReferenceDllName(item); bool isSilverlight = IsSilverlightProject(project); string path = GetAssemblyPath(dllName, isSilverlight); if (String.IsNullOrEmpty(path)) { path = GetReferencePath(msBuildLoader, item, projectDir); } if (!string.IsNullOrEmpty(path)) { reference = new AssemblyReference(path); reference.SetAliasesString(aliases); project.AddReference(reference); } else { reference = project.AddReferenceByName(item.FinalItemSpec, aliases); } return reference; }
private string GetReferencePath(MsBuildProjectLoader msBuildLoader, BuildItem item, string projectDir) { string path = GetAssemblyPathFromHintPath(item, projectDir); if (string.IsNullOrEmpty(path)) { path = GetAssemblyPathFromProjectOutput(msBuildLoader, item, projectDir); } if (string.IsNullOrEmpty(path)) { path = GetAssemblyPathFromAssemblyFolders(msBuildLoader, item); } if (string.IsNullOrEmpty(path)) { path = GetAssemblyPathFromVSInstalDir(item); } if (string.IsNullOrEmpty(path)) { path = GetAssemblyPathFromInclude(item, projectDir); } return path; }
private string GetAssemblyPathFromProjectOutput(MsBuildProjectLoader msBuildLoader, BuildItem item, string projectDir) { string outputPath = msBuildLoader.Project.GetEvaluatedProperty(STR_OutputPath); if (string.IsNullOrEmpty(outputPath)) { return null; } outputPath = PathUtilities.GetPath(projectDir, outputPath); string path = Path.Combine(outputPath, GetReferenceDllName(item) + ".dll"); if (File.Exists(path)) { return path; } return null; }