예제 #1
0
        protected override void ExecuteTask()
        {
            Log(Level.Info, "Starting solution build.");

            if (SolutionFile != null) {
                if (!SolutionFile.Exists) {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                        "Couldn't find solution file '{0}'.", SolutionFile.FullName),
                        Location);
                }
            }

            if (Projects.FileNames.Count > 0) {
                Log(Level.Verbose, "Included projects:" );
                foreach (string projectFile in Projects.FileNames) {
                    Log(Level.Verbose, " - " + projectFile);
                }
            }

            if (ReferenceProjects.FileNames.Count > 0) {
                Log(Level.Verbose, "Reference projects:");
                foreach (string projectFile in ReferenceProjects.FileNames) {
                    Log(Level.Verbose, " - " + projectFile);
                }
            }

            string basePath = null;

            try {
                using (TempFileCollection tfc = new TempFileCollection()) {
                    // store the temp dir so we can clean it up later
                    basePath = tfc.BasePath;

                    // ensure temp directory exists
                    if (!LongPathDirectory.Exists(tfc.BasePath)) {
                        LongPathDirectory.Create(tfc.BasePath);
                    }

                    // create temporary domain
                    PermissionSet tempDomainPermSet = new PermissionSet(PermissionState.Unrestricted);

                    AppDomain temporaryDomain = AppDomain.CreateDomain("temporaryDomain", AppDomain.CurrentDomain.Evidence,
                        AppDomain.CurrentDomain.SetupInformation, tempDomainPermSet);

                    try {
                        ReferencesResolver referencesResolver =
                            ((ReferencesResolver) temporaryDomain.CreateInstanceFrom(Assembly.GetExecutingAssembly().Location,
                            typeof(ReferencesResolver).FullName).Unwrap());

                        using (GacCache gacCache = new GacCache(this.Project)) {
                            SolutionBase sln = SolutionFactory.LoadSolution(this,
                                tfc, gacCache, referencesResolver);
                            if (!sln.Compile(_configuration)) {
                                throw new BuildException("Project build failed.", Location);
                            }
                        }
                    } finally {
                        // unload temporary domain
                        AppDomain.Unload(temporaryDomain);
                    }
                }
            } finally {
                if (basePath != null && LongPathDirectory.Exists(basePath)) {
                    Log(Level.Debug, "Cleaning up temp folder '{0}'.", basePath);

                    // delete temporary directory and all files in it
                    DeleteTask deleteTask = new DeleteTask();
                    deleteTask.Project = Project;
                    deleteTask.Parent = this;
                    deleteTask.InitializeTaskConfiguration();
                    deleteTask.Directory = new DirectoryInfo(basePath);
                    deleteTask.Threshold = Level.None; // no output in build log
                    deleteTask.Execute();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Generates the license file.
        /// </summary>
        protected override void ExecuteTask() {
            FileInfo licensesFile = null;

            // ensure base directory is set, even if fileset was not initialized
            // from XML
            if (Assemblies.BaseDirectory == null) {
                Assemblies.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
            }

            // get the output .licenses file
            if (OutputFile == null) {
                try {
                    licensesFile = new FileInfo(Project.GetFullPath(Target + ".licenses"));
                } catch (Exception ex) {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture, 
                        ResourceUtils.GetString("NA2015"), Target), Location, ex);
                }
            } else {
                licensesFile = OutputFile;
            }

            // make sure the directory for the .licenses file exists
            if (!licensesFile.Directory.Exists) {
                licensesFile.Directory.Create();
            }

            // determine whether .licenses file need to be recompiled
            if (!NeedsCompiling(licensesFile)) {
                return;
            }

            Log(Level.Verbose, ResourceUtils.GetString("String_CompilingLicenseUsingTarget"),
                InputFile.FullName, licensesFile.FullName, Target);

            if (HasCommandLineCompiler) {
                // the command line compiler does not allow us to specify the 
                // full path to the output file, so we have it create the licenses
                // file in a temp directory, and copy it to its actual output
                // location

                // use a newly created temporary directory as working directory
                BaseDirectory = FileUtils.GetTempDirectory();

                try {
                    // set target assembly for generated licenses file
                    Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
                        "/target:\"{0}\"", Target)));
                    // set input filename
                    Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
                        "/complist:\"{0}\"", InputFile.FullName)));
                    // set output directory
                    Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
                        "/outdir:\"{0}\"", BaseDirectory.FullName)));
                    // suppress display of startup banner
                    Arguments.Add(new Argument("/nologo"));
                    // adjust verbosity of tool if necessary
                    if (Verbose) {
                        Arguments.Add(new Argument("/v"));
                    }
                    // use command line tool to compile licenses file
                    base.ExecuteTask();

                    // delete any existing output file
                    if (File.Exists(licensesFile.FullName)) {
                        File.Delete(licensesFile.FullName);
                    }

                    // copy licenses file to output file (with overwrite)
                    File.Copy(Path.Combine(BaseDirectory.FullName, Target + ".licenses"), 
                        licensesFile.FullName, true);
                } finally {
                    // delete temporary directory and all files in it
                    DeleteTask deleteTask = new DeleteTask();
                    deleteTask.Project = Project;
                    deleteTask.Parent = this;
                    deleteTask.InitializeTaskConfiguration();
                    deleteTask.Directory = BaseDirectory;
                    deleteTask.Threshold = Level.None; // no output in build log
                    deleteTask.Execute();
                }
            } else {
                // create new domain
#if (NET_4_0)
                AppDomain newDomain = AppDomain.CreateDomain("LicenseGatheringDomain");
                LicenseGatherer licenseGatherer = (LicenseGatherer)
                    newDomain.CreateInstanceAndUnwrap(typeof(LicenseGatherer).Assembly.FullName,
                    typeof(LicenseGatherer).FullName, false, BindingFlags.Public | BindingFlags.Instance,
                    null, new object[0], CultureInfo.InvariantCulture, new object[0]);
#else
                AppDomain newDomain = AppDomain.CreateDomain("LicenseGatheringDomain", 
                    AppDomain.CurrentDomain.Evidence);
                LicenseGatherer licenseGatherer = (LicenseGatherer)
                    newDomain.CreateInstanceAndUnwrap(typeof(LicenseGatherer).Assembly.FullName,
                    typeof(LicenseGatherer).FullName, false, BindingFlags.Public | BindingFlags.Instance,
                    null, new object[0], CultureInfo.InvariantCulture, new object[0],
                    AppDomain.CurrentDomain.Evidence);
#endif
                licenseGatherer.CreateLicenseFile(this, licensesFile.FullName);

                // unload newly created domain
                AppDomain.Unload(newDomain);
            }
        }
예제 #3
0
파일: RegAsmTask.cs 프로젝트: RoastBoy/nant
        /// <summary>
        /// Registers or unregisters a single assembly, or a group of assemblies.
        /// </summary>
        protected override void ExecuteTask() {
            if (AssemblyFile == null && Assemblies.FileNames.Count == 0) {
                return;
            }

            // when reference assembly are specified, we copy all references 
            // and all assemblies to a temp directory and run regasm from there
            if (References.FileNames.Count != 0) {
                // use a newly created temporary directory as working directory
                BaseDirectory = FileUtils.GetTempDirectory();
            }

            if (Unregister) {
               _arguments.Append(" /unregister");
            }
            if (TypeLib != null) {
                _arguments.AppendFormat(CultureInfo.InvariantCulture,
                    " /tlb:\"{0}\"", TypeLib.FullName);
            }
            if (CodeBase) {
                _arguments.Append(" /codebase");
            }
            if (RegistryFile != null) {
                _arguments.AppendFormat(CultureInfo.InvariantCulture,
                    " /regfile:\"{0}\"", RegistryFile.FullName);
            }
            if (Registered) {
                _arguments.Append(" /registered");
            }
            if (Verbose) {
                _arguments.Append(" /verbose");
            } else {
                _arguments.Append(" /silent");
            }
            _arguments.Append(" /nologo");

            if (AssemblyFile != null) {
                Log(Level.Info, "{0} '{1}' for COM Interop", 
                    Unregister ? "Unregistering" : "Registering", 
                    AssemblyFile.FullName);
                _arguments.AppendFormat(" \"{0}\"", GetAssemblyPath(
                    AssemblyFile.FullName));
            } else {
                // display build log message
                Log(Level.Info, "{0} {1} files for COM interop", 
                    Unregister ? "UnRegistering" : "Registering", 
                    Assemblies.FileNames.Count);

                // add files to command line
                foreach (string path in Assemblies.FileNames) {
                    Log(Level.Verbose, "{0} '{1}' for COM Interop", 
                        Unregister ? "UnRegistering" : "Registering", 
                        path);

                    _arguments.AppendFormat(" \"{0}\"", GetAssemblyPath(path));
                }
            }

            try {
                // call base class to do the work
                base.ExecuteTask();
            } finally {
                // we only need to remove temporary directory if it was
                // actually created
                if (_workingDirectory != null) {
                    // delete temporary directory and all files in it
                    DeleteTask deleteTask = new DeleteTask();
                    deleteTask.Project = Project;
                    deleteTask.Parent = this;
                    deleteTask.InitializeTaskConfiguration();
                    deleteTask.Directory = _workingDirectory;
                    deleteTask.Threshold = Level.None; // no output in build log
                    deleteTask.Execute();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Removes wrapper assembly from build directory, if wrapper assembly 
        /// no longer exists in output directory or is not in sync with build 
        /// directory, to force rebuild.
        /// </summary>
        /// <param name="config">The project configuration.</param>
        private void Sync(ConfigurationBase config)
        {
            if (!CopyLocal || !File.Exists(WrapperAssembly)) {
                // nothing to synchronize
                return;
            }

            // determine path where wrapper assembly should be deployed to
            string outputFile = FileUtils.CombinePaths(config.OutputDir.FullName,
                Path.GetFileName(WrapperAssembly));

            // determine last modification date/time of built wrapper assembly
            DateTime wrapperModTime = File.GetLastWriteTime(WrapperAssembly);

            // rebuild wrapper assembly if output assembly is more recent,
            // or have been removed (by the user) to force a rebuild
            if (FileSet.FindMoreRecentLastWriteTime(outputFile, wrapperModTime) != null) {
                // remove wrapper assembly to ensure a rebuild is performed
                DeleteTask deleteTask = new DeleteTask();
                deleteTask.Project = SolutionTask.Project;
                deleteTask.Parent = SolutionTask;
                deleteTask.InitializeTaskConfiguration();
                deleteTask.File = new FileInfo(WrapperAssembly);
                deleteTask.Threshold = Level.None; // no output in build log
                deleteTask.Execute();
            }
        }
예제 #5
0
파일: ResGenTask.cs 프로젝트: RoastBoy/nant
        private void WriteCommandLineOptions(FileInfo inputFile, FileInfo outputFile) {
            if (!NeedsCompiling(inputFile, outputFile)) {
                return;
            }

            // ensure output directory exists
            if (!outputFile.Directory.Exists) {
                outputFile.Directory.Create();
            }

            string cmdLineArg = string.Format(CultureInfo.InvariantCulture, 
                "\"{0},{1}\" ", inputFile, outputFile.FullName);

            // check if adding arguments to compile current resx to 
            // total command line would cause it to exceed maximum
            // length
            bool maxCmdLineExceeded = (_arguments.Length + cmdLineArg.Length > _maxCmdLineLength);

            // if this is the first resx that we're compiling, or the
            // first one of the next execution of the resgen tool, then
            // add options to command line
            if (_arguments.Length == 0 || maxCmdLineExceeded) {
                StringBuilder sb = new StringBuilder ();

                // bug #1415272: first write assembly references, to make sure these
                // are taken into account when calculating the length of the command
                // line
                if (SupportsAssemblyReferences) {
                    foreach (string assembly in Assemblies.FileNames) {
                        sb.AppendFormat (CultureInfo.InvariantCulture,
                            "/r:\"{0}\" ", assembly);
                    }
                }

                if (UseSourcePath) {
                    if (SupportsExternalFileReferences) {
                        sb.Append ("/useSourcePath ");
                    } else {
                        Log(Level.Warning, ResourceUtils.GetString(
                            "String_ResourceCompilerDoesNotSupportExternalReferences"), 
                            Project.TargetFramework.Description);
                    }
                }
                sb.Append ("/compile ");
                sb.Append (cmdLineArg);
                cmdLineArg = sb.ToString ();
            }

            // if maximum length would have been exceeded by compiling
            // the current resx file, then first execute the resgen
            // tool
            if (maxCmdLineExceeded) {
                try {
                    // call base class to do the work
                    base.ExecuteTask();
                } catch {
                    // we only need to remove temporary directory when 
                    // an error occurred and if it was actually created
                    if (_workingDirectory != null) {
                        // delete temporary directory and all files in it
                        DeleteTask deleteTask = new DeleteTask();
                        deleteTask.Project = Project;
                        deleteTask.Parent = this;
                        deleteTask.InitializeTaskConfiguration();
                        deleteTask.Directory = _workingDirectory;
                        deleteTask.Threshold = Level.None; // no output in build log
                        deleteTask.Execute();
                    }

                    // rethrow exception
                    throw;
                }

                // reset command line arguments as we've processed them
                _arguments.Length = 0;
            }

            // append command line arguments to compile current resx
            // file to the total command line
            _arguments.Append(cmdLineArg);
        }
예제 #6
0
파일: ResGenTask.cs 프로젝트: RoastBoy/nant
        /// <summary>
        /// Converts a single file or group of files.
        /// </summary>
        protected override void ExecuteTask() {
            // ensure base directory is set, even if fileset was not initialized
            // from XML
            if (Assemblies.BaseDirectory == null) {
                Assemblies.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
            }
            if (Resources.BaseDirectory == null) {
                Resources.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
            }

            // clear buffer
            _arguments.Length = 0;

            if (Resources.FileNames.Count > 0 || QualifiedResources.Count > 0) {
                if (OutputFile != null) {
                    throw new BuildException(ResourceUtils.GetString("NA2026"), Location);
                }

                foreach (string fileName in Resources.FileNames) {
                    FileInfo inputFile = new FileInfo(fileName);
                    FileInfo outputFile = GetOutputFile(new FileInfo(Path.Combine(
                        inputFile.DirectoryName, Resources.GetManifestResourceName(fileName))));
                    WriteCommandLineOptions(inputFile, outputFile);
                }

                // used by <solution> task
                foreach (QualifiedResource resource in QualifiedResources) {
                    WriteCommandLineOptions(resource.Input, resource.Output);
                }
            } else {
                // Single file situation
                if (InputFile == null) {
                    throw new BuildException(ResourceUtils.GetString("NA2027"), Location);
                }

                FileInfo outputFile = GetOutputFile(InputFile);

                if (NeedsCompiling(InputFile, outputFile)) {
                    // ensure output directory exists
                    if (!outputFile.Directory.Exists) {
                        outputFile.Directory.Create();
                    }

                    if (UseSourcePath) {
                        if (SupportsExternalFileReferences) {
                            _arguments.Append("/useSourcePath");
                        } else {
                            Log(Level.Warning, ResourceUtils.GetString(
                                "String_ResourceCompilerDoesNotSupportExternalReferences"), 
                                Project.TargetFramework.Description);
                        }
                    }

                    _arguments.Append(string.Format(CultureInfo.InvariantCulture, 
                        " \"{0}\" \"{1}\"", InputFile.FullName, outputFile.FullName));
                }
            }

            if (_arguments.Length != 0) {
                try {
                    // call base class to do the work
                    base.ExecuteTask();
                } finally {
                    // we only need to remove temporary directory if it was
                    // actually created
                    if (_workingDirectory != null) {
                        // delete temporary directory and all files in it
                        DeleteTask deleteTask = new DeleteTask();
                        deleteTask.Project = Project;
                        deleteTask.Parent = this;
                        deleteTask.InitializeTaskConfiguration();
                        deleteTask.Directory = _workingDirectory;
                        deleteTask.Threshold = Level.None; // no output in build log
                        deleteTask.Execute();
                    }
                }
            }
        }