以编程方式构建项目 - 如何添加引用路径

时间:2015-07-21 11:29:14

标签: c# reference msbuild

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");
}

嗨,我需要在执行构建之前添加引用路径(就像在视觉中一样)。我该怎么做

1 个答案:

答案 0 :(得分:0)

您可以使用Assembly.LoadFrom Method这样(根据文件名或路径加载程序集。):

Assembly assembly = Assembly.LoadFrom("Path of the DLL");
相关问题