/// <summary> /// Gets scope public key token. /// </summary> /// <param name="scope">The metadata scope.</param> /// <returns>Returns PublicKeyToken string is exists otherwise empty string.</returns> public static string GetScopePublicKeyToken(this IMetadataScope scope) { var assemblyNameRef = GetAssemblyNameRefByMetadataScope(scope); return((assemblyNameRef != null) ? _publicKeyTokenConverter.ConvertFrom(assemblyNameRef.PublicKeyToken) : null); }
/// <summary> /// Create project reference. In some cases the Visual Studio returns incorrect project output path. /// </summary> /// <param name="projectRef">The project reference.</param> /// <returns>Returns project reference assembly.</returns> private ProjectReference CreateProjectReference(Reference3 projectRef) { if (projectRef.SourceProject == null) { return(BuildProjectReference(projectRef.Name, projectRef.Identity, projectRef.Path, projectRef.Version, projectRef.Culture, projectRef.PublicKeyToken)); } if (!File.Exists(projectRef.Path)) { return(null); } var activeConfiguration = Project.DTE.Solution.SolutionBuild.ActiveConfiguration.Name; var assemblyName = Path.GetFileName(projectRef.Path); var pattern = string.Format(@"\\(obj|bin)\\(?<Configuration>(Release|Debug))\\{0}", assemblyName); var regex = Regex.Match(projectRef.Path, pattern); if (regex.Success) { var projectRefConfiguration = regex.Groups["Configuration"].Value.ToString(); if (projectRefConfiguration.Equals(activeConfiguration, StringComparison.Ordinal) && File.Exists(projectRef.Path)) { return(BuildProjectReference(projectRef.Name, projectRef.Identity, projectRef.Path, projectRef.Version, projectRef.Culture, projectRef.PublicKeyToken)); } } var wrapper = DTEHelper.CreateProjectWrapper(projectRef.SourceProject); var assemblyDef = wrapper.AssemblyDefinition; return(BuildProjectReference(projectRef.Name, projectRef.Identity, wrapper.GetOutputAssemblyPath(), assemblyDef.Name.Version.ToString(), assemblyDef.Name.Culture, _tokenConverter.ConvertFrom(assemblyDef.Name.PublicKeyToken))); }