简体   繁体   English

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

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

Hi, I need add reference path before execution building (like in the visual). 嗨,我需要在执行构建之前添加引用路径(如在视觉上)。 How should I do this. 我应该怎么做。

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

Assembly assembly = Assembly.LoadFrom("Path of the DLL");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM