public string GetManifestResourceName(Configuration solutionConfiguration) { // obtain project configuration (corresponding with solution configuration) ConfigurationSettings projectConfig = (ConfigurationSettings)Project.BuildConfigurations[solutionConfiguration]; switch (Project.Type) { case ProjectType.CSharp: return(GetManifestResourceNameCSharp(projectConfig, _dependentFile)); case ProjectType.VB: return(GetManifestResourceNameVB(projectConfig, _dependentFile)); case ProjectType.JSharp: return(GetManifestResourceNameJSharp(projectConfig, _dependentFile)); default: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unsupported project type '{0}'.", Project.Type)); } }
/// <summary> /// Gets the intermediate build directory in which the satellite /// assembly is built. /// </summary> /// <param name="projectConfig">The project build configuration.</param> /// <returns> /// The intermediate build directory in which the satellite assembly /// is built. /// </returns> public DirectoryInfo GetBuildDirectory(ConfigurationSettings projectConfig) { return new DirectoryInfo(FileUtils.CombinePaths( projectConfig.ObjectDir.FullName, Culture.Name)); }
/// <summary> /// Gets a <see cref="FileInfo" /> representing the path to the /// intermediate file location of the satellite assembly. /// </summary> /// <param name="projectConfig">The project build configuration.</param> /// <param name="projectSettings">The project settings.</param> /// <returns> /// A <see cref="FileInfo" /> representing the path to the /// intermediate file location of the satellite assembly. /// </returns> public FileInfo GetSatelliteAssemblyPath(ConfigurationSettings projectConfig, ProjectSettings projectSettings) { DirectoryInfo buildDir = GetBuildDirectory(projectConfig); return new FileInfo(FileUtils.CombinePaths(buildDir.FullName, GetSatelliteFileName(projectSettings))); }
/// <summary> /// Generates a type library for the specified assembly, registers it. /// </summary> /// <param name="config">The project configuration that is built.</param> /// <param name="solutionConfiguration">The solution configuration that is built.</param> /// <param name="typelibPath">The path of the type library to generate.</param> /// <remarks> /// The <c>regasm</c> tool is used to generate the type library. /// </remarks> private void RegisterForComInterop(ConfigurationSettings config, Configuration solutionConfiguration, string typelibPath) { Log(Level.Verbose, "Registering project output for COM Interop..."); // create and initialize regasm task RegAsmTask regasm = CreateRegAsmTask(); // add assembly references foreach (ReferenceBase reference in References) { StringCollection assemblyReferences = reference.GetAssemblyReferences( solutionConfiguration); foreach (string assemblyFile in assemblyReferences) { regasm.References.Includes.Add(assemblyFile); } } // assembly to register for COM interop regasm.AssemblyFile = new FileInfo(config.BuildPath); // type library to create regasm.TypeLib = new FileInfo(typelibPath); // increment indentation level regasm.Project.Indent(); try { // execute task regasm.Execute(); } finally { // restore indentation level regasm.Project.Unindent(); } }
/// <summary> /// Unregister a type library for the specified assembly, and the types /// in that assembly. /// </summary> /// <param name="config">The project configuration that is built.</param> /// <param name="solutionConfiguration">The solution configuration that is built.</param> /// <remarks> /// The <c>regasm</c> tool is used to unregister the type library, and /// remove the COM registration for types in the specified assembly. /// </remarks> private void UnregisterForComInterop(ConfigurationSettings config, Configuration solutionConfiguration) { // if COM interop registration is not enabled or the previous project // output does not exist, then there's nothing to do if (!config.RegisterForComInterop || !File.Exists(config.OutputPath)) { return; } Log(Level.Verbose, "Unregistering project output for COM Interop..."); // create and initialize regasm task RegAsmTask regasm = CreateRegAsmTask(); // add assembly references foreach (ReferenceBase reference in References) { StringCollection assemblyReferences = reference.GetAssemblyReferences( solutionConfiguration); foreach (string assemblyFile in assemblyReferences) { regasm.References.Includes.Add(assemblyFile); } } // unregister types regasm.Unregister = true; // assembly to unregister regasm.AssemblyFile = new FileInfo(config.OutputPath); // determine path for type library string typeLibPath = GetTypeLibraryPath(config); // if the type library exists, unregister it if (File.Exists(typeLibPath)) { regasm.TypeLib = new FileInfo(typeLibPath); } // increment indentation level regasm.Project.Indent(); try { regasm.Execute(); } finally { // restore indentation level regasm.Project.Unindent(); } }
private bool PreBuild(ConfigurationSettings cs) { string buildCommandLine = ProjectSettings.PreBuildEvent; // check if there are pre build commands to be run if (buildCommandLine != null) { string batchFile = FileUtils.CombinePaths(cs.OutputDir.FullName, "PreBuildEvent.bat"); string workingDirectory = cs.OutputDir.FullName; return ExecuteBuildEvent("PreBuildEvent", buildCommandLine, batchFile, workingDirectory, cs); } // nothing to do, signal success return true; }
private bool PostBuild(ConfigurationSettings cs, bool bCompileSuccess, bool bOutputUpdated) { string buildCommandLine = ProjectSettings.PostBuildEvent; // check if there are post build commands to be run if (buildCommandLine != null) { Log(Level.Debug, "PostBuild commandline: {0}", buildCommandLine); string batchFile = FileUtils.CombinePaths(cs.OutputDir.FullName, "PostBuildEvent.bat"); string workingDirectory = cs.OutputDir.FullName; bool bBuildEventSuccess; // there are three different settings for when the PostBuildEvent should be run switch (ProjectSettings.RunPostBuildEvent) { case "OnBuildSuccess": // post-build event will run if the build succeeds. Thus, // the event will even run for a project that is up-to-date, // as long as the build succeeds if (bCompileSuccess) { Log(Level.Debug, "PostBuild+OnBuildSuccess+bCompileSuccess"); bBuildEventSuccess = ExecuteBuildEvent("PostBuildEvent", buildCommandLine, batchFile, workingDirectory, cs); } else { Log(Level.Debug, "PostBuild+OnBuildSuccess"); bBuildEventSuccess = true; } break; case "Always": // post-build event will run regardless of whether the // build succeeded Log(Level.Debug, "PostBuild+Always"); bBuildEventSuccess = ExecuteBuildEvent("PostBuildEvent", buildCommandLine, batchFile, workingDirectory, cs); break; case "OnOutputUpdated": // post-build event will only run when the compiler's // output file (.exe or .dll) is different than the // previous compiler output file. Thus, a post-build // event will not run if a project is up-to-date if (bOutputUpdated) { Log(Level.Debug, "PostBuild+OnOutputUpdated+bOutputUpdated"); bBuildEventSuccess = ExecuteBuildEvent("PostBuildEvent", buildCommandLine, batchFile, workingDirectory, cs); } else { Log(Level.Debug, "PostBuild+OnOutputUpdated"); bBuildEventSuccess = true; } break; default: // getting here means unknown values in the RunPostBuildEvent // property bBuildEventSuccess = false; break; } return bBuildEventSuccess; } // nothing to do, signal success return true; }
/// <summary> /// Gets the absolute path of the type library for the project /// output. /// </summary> /// <param name="config">The configuration to build.</param> /// <returns> /// The absolute path of the type library for the project output. /// </returns> private string GetTypeLibraryPath(ConfigurationSettings config) { if (config == null) { throw new ArgumentNullException("config"); } return Path.ChangeExtension(config.OutputPath, ".tlb"); }
/// <summary> /// Initializes a new instance of the <see cref="ManagedProjectBase"/> class. /// </summary> /// <param name="solution">The solution.</param> /// <param name="projectPath">The project path.</param> /// <param name="xmlDefinition">The XML definition.</param> /// <param name="solutionTask">The solution task.</param> /// <param name="tfc">The TFC.</param> /// <param name="gacCache">The gac cache.</param> /// <param name="refResolver">The reference resolver.</param> /// <param name="outputDir">The output dir.</param> /// <exception cref="System.ArgumentNullException"> /// projectPath /// or /// xmlDefinition /// </exception> protected ManagedProjectBase(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { if (projectPath == null) { throw new ArgumentNullException("projectPath"); } if (xmlDefinition == null) { throw new ArgumentNullException("xmlDefinition"); } _references = new ArrayList(); _neutralResources = new ArrayList(); _localizedResources = new ArrayList(); _sourceFiles = CollectionsUtil.CreateCaseInsensitiveHashtable(); _projectPath = projectPath; _projectLocation = DetermineProjectLocation(xmlDefinition); if (!IsWebProject) { _projectDirectory = new FileInfo(projectPath).Directory; } else { string projectDirectory = projectPath.Replace(":", "_"); projectDirectory = projectDirectory.Replace("/", "_"); projectDirectory = projectDirectory.Replace("\\", "_"); _projectDirectory = new DirectoryInfo(FileUtils.CombinePaths( TemporaryFiles.BasePath, projectDirectory)); // ensure project directory exists if (!_projectDirectory.Exists) { _projectDirectory.Create(); _projectDirectory.Refresh(); } _webProjectBaseUrl = projectPath.Substring(0, projectPath.LastIndexOf("/")); } _projectSettings = new ProjectSettings(xmlDefinition, (XmlElement) xmlDefinition.SelectSingleNode("//Build/Settings"), this); XmlNodeList nlConfigurations = xmlDefinition.SelectNodes("//Config"); foreach (XmlElement elemConfig in nlConfigurations) { ConfigurationSettings cs = new ConfigurationSettings(this, elemConfig, OutputDir); ProjectConfigurations[Configuration.Parse(cs.Name)] = cs; } XmlNodeList nlReferences = xmlDefinition.SelectNodes("//References/Reference"); foreach (XmlElement elemReference in nlReferences) { ReferenceBase reference = CreateReference(solution, elemReference); _references.Add(reference); } XmlNodeList nlFiles = xmlDefinition.SelectNodes("//Files/Include/File"); foreach (XmlElement elemFile in nlFiles) { string buildAction = StringUtils.ConvertEmptyToNull(elemFile.GetAttribute("BuildAction")); string sourceFile; if (!String.IsNullOrEmpty(elemFile.GetAttribute("Link"))) { sourceFile = FileUtils.GetFullPath(FileUtils.CombinePaths( ProjectDirectory.FullName, elemFile.GetAttribute("Link"))); } else { sourceFile = FileUtils.GetFullPath(FileUtils.CombinePaths( ProjectDirectory.FullName, elemFile.GetAttribute("RelPath"))); } if (IsWebProject) { WebDavClient wdc = new WebDavClient(new Uri(_webProjectBaseUrl)); wdc.DownloadFile(sourceFile, elemFile.Attributes["RelPath"].Value); switch (buildAction) { case "Compile": _sourceFiles[sourceFile] = null; break; case "EmbeddedResource": RegisterEmbeddedResource(sourceFile, elemFile); break; case null: if (string.Compare(Path.GetExtension(sourceFile), FileExtension, true, CultureInfo.InvariantCulture) == 0) { _sourceFiles[sourceFile] = null; } break; } } else { switch (buildAction) { case "Compile": _sourceFiles[sourceFile] = null; break; case "EmbeddedResource": RegisterEmbeddedResource(sourceFile, elemFile); break; case null: if (string.Compare(Path.GetExtension(sourceFile), FileExtension, true, CultureInfo.InvariantCulture) == 0) { _sourceFiles[sourceFile] = null; } break; } // check if file is "App.config" (using case-insensitive comparison) if (string.Compare("App.config", elemFile.GetAttribute("RelPath"), true, CultureInfo.InvariantCulture) == 0) { // App.config is only an output file for executable projects if (ProjectSettings.OutputType == ManagedOutputType.Executable || ProjectSettings.OutputType == ManagedOutputType.WindowsExecutable) { ExtraOutputFiles[sourceFile] = ProjectSettings.OutputFileName + ".config"; } } } } }
private string GetManifestResourceNameJSharp(ConfigurationSettings configSetting, string dependentFile) { // defer to the resource management code in VjcTask VjcTask vjc = new VjcTask(); vjc.Project = _solutionTask.Project; vjc.NamespaceManager = _solutionTask.NamespaceManager; vjc.OutputFile = new FileInfo(FileUtils.CombinePaths(configSetting.OutputDir.FullName, Project.ProjectSettings.OutputFileName)); // set-up resource fileset ResourceFileSet resources = new ResourceFileSet(); resources.Project = _solutionTask.Project; resources.NamespaceManager = _solutionTask.NamespaceManager; resources.Parent = vjc; resources.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName( Project.ProjectPath)); resources.Prefix = Project.ProjectSettings.RootNamespace; resources.DynamicPrefix = true; // bug #1042917: use logical location of resource file to determine // manifest resource name return vjc.GetManifestResourceName(resources, InputFile.FullName, LogicalFile.FullName, dependentFile); }