我希望能够以编程方式发布单独的C#项目。当我运行以下代码时,我希望它发布我的Repair.csproj
项目。
我在这里做的是我从我的代码中获取版本号。然后我将其递增1,删除发布文件夹中的所有内容,然后尝试发布我的项目。
但是,当我运行此代码时,它不会发布我的Repair.csproj
。我不知道我哪里出错了。
我的代码如下
public const string publishLocation = @"C:\Workspace_User\Repair\MAIN\Publish";
public const string RepairLocation = @"C:\Workspace_User\Repair\MAIN\Repair.sln";
public const string repairproj = @"C:\Workspace_User\Repair\MAIN\Repair\Repair.csproj";
public const string r = @"C:\Workspace_User\Repair\MAIN\Repair\bin\Release\Repair.dll";
static void Main(string[] args)
{
Microsoft.Build.BuildEngine.Engine.GlobalEngine.BuildEnabled = true;
System.IO.DirectoryInfo di = new DirectoryInfo(publishLocation);
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(RepairLocation);
var version= AssemblyName.GetAssemblyName(r).Version;
var splitVersionNumber= version.ToString().Split('.');
var getNumber = splitVersionNumber[3];
var addInt=Convert.ToInt32(getNumber);
addInt++;
foreach (FileInfo file in di.GetFiles())
{
if (file.Name!="Working Folder")
{
file.Delete();
}
}
buildMethod();
}
public static object buildMethod()
{
var props = new Dictionary<string, string>();
props["Configuration"] = "Publish";
var request = new BuildRequestData(repairproj, props, null, new string[] { "Build" }, null);
var parms = new BuildParameters();
// parms.Loggers = ...;
var result = BuildManager.DefaultBuildManager.Build(parms, request);
Debug.Write(result);
return result.OverallResult == BuildResultCode.Success;
}