Exemplo n.º 1
0
        /// <summary>
        /// Finds all build products from this project. This includes content and other assemblies marked to be copied local.
        /// </summary>
        /// <param name="OutputDir">The output directory</param>
        /// <param name="BuildProducts">Receives the set of build products</param>
        /// <param name="ProjectFileToInfo">Map of project file to information, to resolve build products from referenced projects copied locally</param>
        public void FindBuildProducts(DirectoryReference OutputDir, HashSet <FileReference> BuildProducts, Dictionary <FileReference, CsProjectInfo> ProjectFileToInfo)
        {
            // Add the standard build products
            FindCompiledBuildProducts(OutputDir, BuildProducts);

            // Add the referenced assemblies which are marked to be copied into the output directory. This only happens for the main project, and does not happen for referenced projects.
            foreach (KeyValuePair <FileReference, bool> Reference in References)
            {
                if (Reference.Value)
                {
                    FileReference OutputFile = FileReference.Combine(OutputDir, Reference.Key.GetFileName());
                    AddReferencedAssemblyAndSupportFiles(OutputFile, BuildProducts);
                }
            }

            // Copy the build products for any referenced projects. Note that this does NOT operate recursively.
            foreach (KeyValuePair <FileReference, bool> ProjectReference in ProjectReferences)
            {
                CsProjectInfo OtherProjectInfo;
                if (ProjectFileToInfo.TryGetValue(ProjectReference.Key, out OtherProjectInfo))
                {
                    OtherProjectInfo.FindCompiledBuildProducts(OutputDir, BuildProducts);
                }
            }

            // Add any copied content. This DOES operate recursively.
            FindCopiedContent(OutputDir, BuildProducts, ProjectFileToInfo);
        }
        /// <summary>
        /// Find all the build products created by compiling the given project file
        /// </summary>
        /// <param name="ProjectFile">Initial project file to read. All referenced projects will also be read.</param>
        /// <param name="InitialProperties">Mapping of property name to value</param>
        /// <param name="OutBuildProducts">Receives a set of build products on success</param>
        /// <returns>True if the build products were found, false otherwise.</returns>
        static bool FindBuildProducts(HashSet <FileReference> ProjectFiles, Dictionary <string, string> InitialProperties, out HashSet <FileReference> OutBuildProducts)
        {
            // Read all the project information into a dictionary
            Dictionary <FileReference, MsBuildProjectInfo> FileToProjectInfo = new Dictionary <FileReference, MsBuildProjectInfo>();

            foreach (FileReference ProjectFile in ProjectFiles)
            {
                if (!ReadProjectsRecursively(ProjectFile, InitialProperties, FileToProjectInfo))
                {
                    OutBuildProducts = null;
                    return(false);
                }
            }

            // Find all the build products
            HashSet <FileReference> BuildProducts = new HashSet <FileReference>();

            foreach (KeyValuePair <FileReference, MsBuildProjectInfo> Pair in FileToProjectInfo)
            {
                MsBuildProjectInfo ProjectInfo = Pair.Value;

                // Add the standard build products
                DirectoryReference OutputDir = ProjectInfo.GetOutputDir(Pair.Key.Directory);
                ProjectInfo.AddBuildProducts(OutputDir, BuildProducts);

                // Add the referenced assemblies
                foreach (FileReference OtherAssembly in ProjectInfo.References.Where(x => x.Value).Select(x => x.Key))
                {
                    FileReference OutputFile = FileReference.Combine(OutputDir, OtherAssembly.GetFileName());
                    BuildProducts.Add(OutputFile);

                    FileReference SymbolFile = OtherAssembly.ChangeExtension(".pdb");
                    if (SymbolFile.Exists())
                    {
                        BuildProducts.Add(OutputFile.ChangeExtension(".pdb"));
                    }
                }

                // Add build products from all the referenced projects. MSBuild only copy the directly referenced build products, not recursive references or other assemblies.
                foreach (MsBuildProjectInfo OtherProjectInfo in ProjectInfo.ProjectReferences.Where(x => x.Value).Select(x => FileToProjectInfo[x.Key]))
                {
                    OtherProjectInfo.AddBuildProducts(OutputDir, BuildProducts);
                }
            }

            // Update the output set
            OutBuildProducts = BuildProducts;
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finds all content which will be copied into the output directory for this project. This includes content from any project references as "copy local" recursively (though MSBuild only traverses a single reference for actual binaries, in such cases)
        /// </summary>
        /// <param name="OutputDir">The output directory</param>
        /// <param name="BuildProducts">Receives the set of build products</param>
        /// <param name="ProjectFileToInfo">Map of project file to information, to resolve build products from referenced projects copied locally</param>
        private void FindCopiedContent(DirectoryReference OutputDir, HashSet <FileReference> OutputFiles, Dictionary <FileReference, CsProjectInfo> ProjectFileToInfo)
        {
            // Copy any referenced projects too.
            foreach (KeyValuePair <FileReference, bool> ProjectReference in ProjectReferences)
            {
                CsProjectInfo OtherProjectInfo;
                if (ProjectFileToInfo.TryGetValue(ProjectReference.Key, out OtherProjectInfo))
                {
                    OtherProjectInfo.FindCopiedContent(OutputDir, OutputFiles, ProjectFileToInfo);
                }
            }

            // Add the content which is copied to the output directory
            foreach (KeyValuePair <FileReference, bool> ContentReference in ContentReferences)
            {
                FileReference ContentFile = ContentReference.Key;
                if (ContentReference.Value)
                {
                    OutputFiles.Add(FileReference.Combine(OutputDir, ContentFile.GetFileName()));
                }
            }
        }