/// <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)));
        }
示例#2
0
 protected override BaseProjectWrapper GetValue(string key)
 {
     return(DTEHelper.CreateProjectWrapper(DTEHelper.GetProjectByName(_serviceProvider, key)));
 }