示例#1
0
        /// <summary>
        /// Main task method
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            // Allow unit tests to inject a non-file system dependent version of this.
            if (GetAssemblyName == null)
            {
                GetAssemblyName = AssemblyName.GetAssemblyName;
            }

            try
            {
                if (!VerifyProjectReferenceItems(ProjectReferences, false /* treat problems as warnings */))
                {
                    return(false);
                }

                ArrayList resolvedPaths        = new ArrayList(ProjectReferences.GetLength(0));
                ArrayList unresolvedReferences = new ArrayList(ProjectReferences.GetLength(0));

                CacheProjectElementsFromXml(PreresolvedProjectOutputs);

                foreach (ITaskItem projectRef in ProjectReferences)
                {
                    bool      resolveSuccess = false;
                    ITaskItem resolvedPath;

                    Log.LogMessageFromResources(MessageImportance.Low, "ResolveNonMSBuildProjectOutput.ProjectReferenceResolutionStarting", projectRef.ItemSpec);

                    resolveSuccess = ResolveProject(projectRef, out resolvedPath);

                    if (resolveSuccess)
                    {
                        if (resolvedPath.ItemSpec.Length > 0)
                        {
                            // VC project system does not look like an MSBuild project type yet because VC do not
                            // yet implement IVSProjectBuildSystem.  So project references to VC managed libraries
                            // need to be recognized as such.
                            // Even after VC implements this IVSProjectBuildSystem, other project types (NMake, NAnt, etc.)
                            // still can generate managed assemblies, in which case we still need to perform this managed
                            // assembly check.
                            try
                            {
                                GetAssemblyName(resolvedPath.ItemSpec);
                                resolvedPath.SetMetadata("ManagedAssembly", "true");
                            }
                            catch (BadImageFormatException)
                            {
                            }

                            resolvedPaths.Add(resolvedPath);

                            Log.LogMessageFromResources(MessageImportance.Low, "ResolveNonMSBuildProjectOutput.ProjectReferenceResolutionSuccess", projectRef.ItemSpec, resolvedPath.ItemSpec);
                        }
                        // If resolved path is empty, log a warning. This means that this reference is not an MSBuild reference,
                        // but could not be resolved in the IDE.
                        else
                        {
                            Log.LogWarningWithCodeFromResources("ResolveNonMSBuildProjectOutput.ProjectReferenceResolutionFailure", projectRef.ItemSpec);
                        }
                    }
                    else
                    {
                        unresolvedReferences.Add(projectRef);

                        // This is not an error - we pass unresolved references to UnresolvedProjectReferences for further
                        // processing in the .targets file.
                        Log.LogMessageFromResources(MessageImportance.Low, "ResolveNonMSBuildProjectOutput.ProjectReferenceUnresolved", projectRef.ItemSpec);
                    }
                }

                ResolvedOutputPaths         = (ITaskItem[])resolvedPaths.ToArray(typeof(ITaskItem));
                UnresolvedProjectReferences = (ITaskItem[])unresolvedReferences.ToArray(typeof(ITaskItem));
            }
            catch (XmlException e)
            {
                Log.LogErrorWithCodeFromResources("General.ErrorExecutingTask", this.GetType().Name, e.Message);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Main task method
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            try
            {
                if (!VerifyProjectReferenceItems(ProjectReferences, true /* treat problems as errors */))
                {
                    return(false);
                }

                ArrayList resolvedReferences   = new ArrayList(ProjectReferences.GetLength(0));
                ArrayList unresolvedReferences = new ArrayList(ProjectReferences.GetLength(0));

                if (!String.IsNullOrEmpty(SolutionConfigurationContents))
                {
                    CacheProjectElementsFromXml(SolutionConfigurationContents);
                }

                if (AddSyntheticProjectReferencesForSolutionDependencies)
                {
                    // The solution may have had project to project dependencies expressed in it, which were passed in with the blob.
                    // Add those to the list of project references as if they were regular project references.
                    AddSyntheticProjectReferences(CurrentProject);
                }

                foreach (ITaskItem projectRef in ProjectReferences)
                {
                    bool      resolveSuccess = false;
                    ITaskItem resolvedReference;

                    resolveSuccess = ResolveProject(projectRef, out resolvedReference);

                    if (resolveSuccess)
                    {
                        resolvedReferences.Add(resolvedReference);

                        Log.LogMessageFromResources(MessageImportance.Low, "AssignProjectConfiguration.ProjectConfigurationResolutionSuccess", projectRef.ItemSpec, resolvedReference.GetMetadata(attrFullConfiguration));
                    }
                    else
                    {
                        // If the reference was unresolved, we want to undefine the Configuration and Platform
                        // global properties, so that the project will build using its default Configuration and
                        // Platform rather than that of its parent.
                        if (ShouldUnsetParentConfigurationAndPlatform)
                        {
                            string globalPropertiesToRemove = projectRef.GetMetadata("GlobalPropertiesToRemove");

                            if (!String.IsNullOrEmpty(globalPropertiesToRemove))
                            {
                                globalPropertiesToRemove += ";";
                            }

                            if (projectRef is ITaskItem2)
                            {
                                ((ITaskItem2)projectRef).SetMetadataValueLiteral("GlobalPropertiesToRemove", globalPropertiesToRemove + "Configuration;Platform");
                            }
                            else
                            {
                                projectRef.SetMetadata("GlobalPropertiesToRemove", EscapingUtilities.Escape(globalPropertiesToRemove + "Configuration;Platform"));
                            }
                        }

                        unresolvedReferences.Add(projectRef);

                        // This is not an error - we pass unresolved references to UnresolvedProjectReferences for further
                        // processing in the .targets file. This means this project was not checked for building in the
                        // active solution configuration.
                        Log.LogMessageFromResources(MessageImportance.Low, "AssignProjectConfiguration.ProjectConfigurationUnresolved", projectRef.ItemSpec);
                    }
                }

                AssignedProjects   = (ITaskItem[])resolvedReferences.ToArray(typeof(ITaskItem));
                UnassignedProjects = (ITaskItem[])unresolvedReferences.ToArray(typeof(ITaskItem));
            }
            catch (XmlException e)
            {
                Log.LogErrorWithCodeFromResources("General.ErrorExecutingTask", this.GetType().Name, e.Message);
                return(false);
            }

            return(true);
        }