以编程方式构建项目 - 如何添加引用路径
Programmatically build project - how to add reference path
ProjectCollection pc = new ProjectCollection();
// THERE ARE A LOT OF PROPERTIES HERE, THESE MAP TO THE MSBUILD CLI PROPERTIES
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("Configuration", "Debug");
globalProperty.Add("Platform", "AnyCPU");
globalProperty.Add("OutputPath", @"c:\Output");
FileLogger logger = new FileLogger();
logger.Parameters = string.Format(@"logfile=C:\build.log");
BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new List<ILogger>() { logger };
BuildRequestData buildRequest = new BuildRequestData(buildFileFullName, globalProperty, "4.0", new string[] { "Build" }, null, BuildRequestDataFlags.ReplaceExistingProjectInstance);
// THIS IS WHERE THE MAGIC HAPPENS - IN PROCESS MSBUILD
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, buildRequest);
// A SIMPLE WAY TO CHECK THE RESULT
if(buildResult.OverallResult == BuildResultCode.Success)
{
Console.WriteLine("ok");
}
else
{
Console.WriteLine("wrong");
}
嗨,我需要在执行构建之前添加参考路径(就像在视觉中一样)。我应该怎么做。
您可以像这样使用 Assembly.LoadFrom Method
(加载给定文件名或路径的程序集。):
Assembly assembly = Assembly.LoadFrom("Path of the DLL");
ProjectCollection pc = new ProjectCollection();
// THERE ARE A LOT OF PROPERTIES HERE, THESE MAP TO THE MSBUILD CLI PROPERTIES
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("Configuration", "Debug");
globalProperty.Add("Platform", "AnyCPU");
globalProperty.Add("OutputPath", @"c:\Output");
FileLogger logger = new FileLogger();
logger.Parameters = string.Format(@"logfile=C:\build.log");
BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new List<ILogger>() { logger };
BuildRequestData buildRequest = new BuildRequestData(buildFileFullName, globalProperty, "4.0", new string[] { "Build" }, null, BuildRequestDataFlags.ReplaceExistingProjectInstance);
// THIS IS WHERE THE MAGIC HAPPENS - IN PROCESS MSBUILD
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, buildRequest);
// A SIMPLE WAY TO CHECK THE RESULT
if(buildResult.OverallResult == BuildResultCode.Success)
{
Console.WriteLine("ok");
}
else
{
Console.WriteLine("wrong");
}
嗨,我需要在执行构建之前添加参考路径(就像在视觉中一样)。我应该怎么做。
您可以像这样使用 Assembly.LoadFrom Method
(加载给定文件名或路径的程序集。):
Assembly assembly = Assembly.LoadFrom("Path of the DLL");