2015-07-21 55 views
0
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"); 
} 

嗨,我需要添加引用路徑之前執行建設(如在視覺)。我應該如何做到這一點。以編程方式建立項目 - 如何添加參考路徑

回答

0

您可以使用Assembly.LoadFrom Method像這樣(加載程序集賦予其文件名或路徑。):

Assembly assembly = Assembly.LoadFrom("Path of the DLL"); 
相關問題