コード例 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Iterate through each collection of assembly names to gather a count of references
        /// to each assembly.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void CountAssemblyReferencesAndReloadFileList()
        {
            CopyFileSet.Reset();
            foreach (StringCollection asmCollection in m_assemblyNamesCollection)
            {
                foreach (string asmName in asmCollection)
                {
                    if (m_assembliesCount.Contains(asmName))
                    {
                        m_assembliesCount[asmName] = (int)m_assembliesCount[asmName] + 1;
                    }
                    else
                    {
                        m_assembliesCount.Add(asmName, 1);
                    }

                    CopyFileSet.Includes.Add(asmName);

                    if (CopyRelated)
                    {
                        CopyFileSet.Includes.Add(Path.ChangeExtension(asmName, ".*"));
                    }
                }
            }
            CopyFileSet.Scan();

            if (Verbose)
            {
                Log(Level.Verbose, "List of assemblies with counts:");
                foreach (DictionaryEntry entry in m_assembliesCount)
                {
                    Log(Level.Verbose, "{0} ({1})", entry.Key, entry.Value);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes the Copy task.
        /// </summary>
        /// <exception cref="BuildException">A assembly that has to be copied does not exist or could not be copied.</exception>
        protected override void ExecuteTask()
        {
            string oldDir  = Directory.GetCurrentDirectory();
            string baseDir = CopyFileSet.BaseDirectory.FullName;

            try
            {
                Directory.SetCurrentDirectory(baseDir);
                foreach (string filename in CopyFileSet.FileNames)
                {
                    ProcessAssembly(filename);
                }

                string name = "(unknown)";
                try
                {
                    // Create directory if not present
                    if (!Directory.Exists(ToDirectory))
                    {
                        Directory.CreateDirectory(ToDirectory);
                        Log(Level.Verbose, "Created directory: {0}", ToDirectory);
                    }
                    // Retrieve all assemblies and related files; exclude files that are in
                    // the exclude list of the file set.
                    CopyFileSet.Reset();
                    foreach (string file in AssemblyNames)
                    {
                        CopyFileSet.Includes.Add(file);
                        if (CopyRelated)
                        {
                            CopyFileSet.Includes.Add(Path.ChangeExtension(file, ".*"));
                        }
                    }
                    CopyFileSet.Scan();

                    // Copy files
                    foreach (string pathname in CopyFileSet.FileNames)
                    {
                        CopyFile(pathname, ref name);
                    }
                }
                catch (Exception ex)
                {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                                               "Cannot copy {0} to {1}.", name, ToDirectory);

                    if (FailOnError)
                    {
                        throw new BuildException(msg, Location, ex);
                    }
                    else
                    {
                        Log(Level.Error, msg);
                    }
                }
                int fileCount = AssemblyNames.Count;
                if (fileCount == 0)
                {
                    Log(Level.Warning, "No files copied.");
                }
                else
                {
                    Log(Level.Info, "Copied {0} file{1} to: {2}", fileCount, (fileCount != 1) ? "s" : "", ToDirectory);
                }
            }
            finally
            {
                Directory.SetCurrentDirectory(oldDir);
            }
        }