Beispiel #1
0
 public Resource(ManagedProjectBase project, FileInfo resourceSourceFile, string resourceSourceFileRelativePath, string dependentFile, SolutionTask solutionTask, GacCache gacCache) {
     _project = project;
     _resourceSourceFile = resourceSourceFile;
     _resourceSourceFileRelativePath = resourceSourceFileRelativePath;
     _dependentFile = dependentFile;
     _solutionTask = solutionTask;
     _culture = CompilerBase.GetResourceCulture(resourceSourceFile.FullName, 
         dependentFile);
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectSettings"/> class.
        /// </summary>
        /// <param name="elemRoot">The elem root.</param>
        /// <param name="elemSettings">The elem settings.</param>
        /// <param name="project">The project.</param>
        /// <exception cref="BuildException"></exception>
        public ProjectSettings(XmlElement elemRoot, XmlElement elemSettings, ManagedProjectBase project)
        {
            _project = project;
            _settings = new ArrayList();

            // check whether build file is valid
            if (elemRoot.FirstChild == null) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    "Project file '{0}' is not valid.", Project.ProjectPath),
                    Location.UnknownLocation);
            }

            _guid = ProjectSettings.GetProjectGuid(project.ProjectPath,
                elemRoot);

            // determine output type of this project
            _outputType = GetOutputType(elemSettings);

            // initialize hashtable for holding string settings
            Hashtable htStringSettings = new Hashtable();

            switch (_outputType) {
                case ManagedOutputType.Library:
                    _settings.Add("/target:library");
                    break;
                case ManagedOutputType.Executable:
                    _settings.Add("/target:exe");
                    // startup object only makes sense for executable assemblies
                    htStringSettings["StartupObject"] = @"/main:""{0}""";
                    break;
                case ManagedOutputType.WindowsExecutable:
                    _settings.Add("/target:winexe");
                    // startup object only makes sense for executable assemblies
                    htStringSettings["StartupObject"] = @"/main:""{0}""";
                    break;
            }

            // suppresses display of Microsoft startup banner
            _settings.Add("/nologo");

            _assemblyName = elemSettings.Attributes["AssemblyName"].Value;

            // the key file to use to sign ActiveX/COM wrappers
            _assemblyOriginatorKeyFile = StringUtils.ConvertEmptyToNull(
                elemSettings.Attributes["AssemblyOriginatorKeyFile"].Value);

            // the key container to use to sign ActiveX/COM wrappers
            _assemblyKeyContainerName = StringUtils.ConvertEmptyToNull(
                elemSettings.Attributes["AssemblyKeyContainerName"].Value);

            // pre and post build events are VS .NET 2003 specific, so do not
            // assume they are there
            if (elemSettings.Attributes["RunPostBuildEvent"] != null) {
                _runPostBuildEvent = StringUtils.ConvertEmptyToNull(
                    elemSettings.Attributes["RunPostBuildEvent"].Value);
            }

            if (elemSettings.Attributes["PreBuildEvent"] != null) {
                _preBuildEvent = StringUtils.ConvertEmptyToNull(
                    elemSettings.Attributes["PreBuildEvent"].Value);
            }

            if (elemSettings.Attributes["PostBuildEvent"] != null) {
                _postBuildEvent = StringUtils.ConvertEmptyToNull(
                    elemSettings.Attributes["PostBuildEvent"].Value);
            }

            if (elemSettings.Attributes["RootNamespace"] != null) {
                _rootNamespace = StringUtils.ConvertEmptyToNull(
                    elemSettings.Attributes["RootNamespace"].Value);
                if (RootNamespace != null && Project.Type == ProjectType.VB) {
                    _settings.Add("/rootnamespace:" + _rootNamespace);
                }
            }

            if (elemSettings.Attributes["ApplicationIcon"] != null) {
                string value = StringUtils.ConvertEmptyToNull(
                    elemSettings.Attributes["ApplicationIcon"].Value);
                if (value != null) {
                    _applicationIcon = new FileInfo(FileUtils.CombinePaths(
                        Project.ProjectDirectory.FullName, value));
                }
            }

            // process VB.NET specific project settings
            if (Project.Type == ProjectType.VB) {
                if (elemSettings.Attributes["OptionExplicit"] != null) {
                    if (elemSettings.Attributes ["OptionExplicit"].Value == "Off") {
                        _settings.Add("/optionexplicit-");
                    } else {
                        _settings.Add("/optionexplicit+");
                    }
                }

                if (elemSettings.Attributes["OptionStrict"] != null) {
                    if (elemSettings.Attributes ["OptionStrict"].Value == "Off") {
                        _settings.Add("/optionstrict-");
                    } else {
                        _settings.Add("/optionstrict+");
                    }
                }

                if (elemSettings.Attributes["OptionCompare"] != null) {
                    if (elemSettings.Attributes ["OptionCompare"].Value == "Text") {
                        _settings.Add("/optioncompare:text");
                    } else {
                        _settings.Add("/optioncompare:binary");
                    }
                }
            }

            foreach (DictionaryEntry de in htStringSettings) {
                string value = elemSettings.GetAttribute(de.Key.ToString());
                if (String.IsNullOrEmpty(value)) {
                    // skip empty values
                    continue;
                }
                _settings.Add(string.Format(de.Value.ToString(), value));
            }
        }
Beispiel #3
0
        public ConfigurationSettings(ManagedProjectBase project, XmlElement elemConfig, DirectoryInfo outputDir)
            : base(project)
        {
            _settings = new ArrayList();
            if (outputDir == null) {
                _relativeOutputDir = elemConfig.Attributes["OutputPath"].Value;
                if (!_relativeOutputDir.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture))) {
                    _relativeOutputDir = _relativeOutputDir + Path.DirectorySeparatorChar;
                }
                _outputDir = new DirectoryInfo(FileUtils.CombinePaths(
                    project.ProjectDirectory.FullName,
                    _relativeOutputDir));
            } else {
                _relativeOutputDir = outputDir.FullName;
                if (!_relativeOutputDir.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture))) {
                    _relativeOutputDir = _relativeOutputDir + Path.DirectorySeparatorChar;
                }
                _outputDir = outputDir;
            }

            _name = elemConfig.GetAttribute("Name");

            string documentationFile = elemConfig.GetAttribute("DocumentationFile");
            if (!String.IsNullOrEmpty(documentationFile)) {
                // to match VS.NET, the XML Documentation file will be output
                // in the project directory, and only later copied to the output
                // directory
                string xmlDocBuildFile = FileUtils.CombinePaths(project.ProjectDirectory.FullName,
                    documentationFile);

                // add compiler option to build XML Documentation file
                _settings.Add(@"/doc:""" + xmlDocBuildFile + @"""");

                // make sure the output directory for the doc file exists
                if (!Directory.Exists(Path.GetDirectoryName(xmlDocBuildFile))) {
                    Directory.CreateDirectory(Path.GetDirectoryName(xmlDocBuildFile));
                }

                // add built documentation file as extra output file
                ExtraOutputFiles[xmlDocBuildFile] = Path.GetFileName(xmlDocBuildFile);
            }

            // determine whether we need to register project output for use with
            // COM components
            _registerForComInterop = string.Compare(elemConfig.GetAttribute("RegisterForComInterop"),
                "true", true, CultureInfo.InvariantCulture) == 0;

            SolutionTask.Log(Level.Debug, "Project: {0} Relative Output Path: {1} Output Path: {2} Documentation Path: {3}",
                Project.Name, _relativeOutputDir, _outputDir.FullName, documentationFile);

            Hashtable htStringSettings = new Hashtable();
            Hashtable htBooleanSettings = new Hashtable();

            htStringSettings["BaseAddress"] = "/baseaddress:{0}";

            // is only supported by csc (all versions) and vbc (2.0 or higher)
            htStringSettings["FileAlignment"] = "/filealign:{0}";

            htStringSettings["DefineConstants"] = "/define:{0}";

            switch (project.Type) {
                case ProjectType.CSharp:
                    htStringSettings["WarningLevel"] = "/warn:{0}";
                    htStringSettings["NoWarn"] = "/nowarn:{0}";
                    htBooleanSettings["IncrementalBuild"] = "/incremental";
                    htBooleanSettings["AllowUnsafeBlocks"] = "/unsafe";
                    htBooleanSettings["CheckForOverflowUnderflow"] = "/checked";
                    break;
                case ProjectType.JSharp:
                    htStringSettings["WarningLevel"] = "/warn:{0}";
                    htStringSettings["NoWarn"] = "/nowarn:{0}";
                    htBooleanSettings["IncrementalBuild"] = "/incremental";
                    break;
                case ProjectType.VB:
                    htStringSettings["DefineDebug"] = "/d:DEBUG={0}";
                    htStringSettings["DefineTrace"] = "/d:TRACE={0}";
                    htBooleanSettings["RemoveIntegerChecks"] = "/removeintchecks";
                    break;
            }

            htBooleanSettings["DebugSymbols"] = "/debug";
            htBooleanSettings["TreatWarningsAsErrors"] = "/warnaserror";
            htBooleanSettings["Optimize"] = "/optimize";

            foreach (DictionaryEntry de in htStringSettings) {
                string name = de.Key.ToString();
                string value = elemConfig.GetAttribute(de.Key.ToString());
                if (!String.IsNullOrEmpty(value)) {
                    switch (name) {
                        case "BaseAddress":
                            // vbc and vjs expect the base address to be specified
                            // as a hexadecimal number, csc supports decimal,
                            // hexadecimal, or octal number
                            //
                            // so use hexadecimal as all compiler support this
                            uint intvalue = Convert.ToUInt32(value, CultureInfo.InvariantCulture);
                            value = "0x" + intvalue.ToString("x", CultureInfo.InvariantCulture);
                            break;
                        case "DefineConstants":
                            // vbc fails when the symbol contains spaces
                            value = value.Replace(" ", string.Empty);
                            break;
                    }
                    _settings.Add(string.Format(CultureInfo.InvariantCulture, de.Value.ToString(), value));
                }
            }

            foreach (DictionaryEntry de in htBooleanSettings) {
                string name = de.Key.ToString();
                switch (name) {
                    case "IncrementalBuild":
                        // ignore if not supported
                        if (!IncrementalBuildSupported) {
                            continue;
                        }
                        break;
                }

                string value = elemConfig.GetAttribute(name);
                if (string.Compare(value, "true", true, CultureInfo.InvariantCulture) == 0) {
                    _settings.Add(de.Value.ToString() + "+");
                } else if (string.Compare(value, "false", true, CultureInfo.InvariantCulture) == 0) {
                    _settings.Add(de.Value.ToString() + "-");
                }
            }

            _settings.Add(string.Format(CultureInfo.InvariantCulture, "/out:\"{0}\"", BuildPath));
        }