2 years ago
#54819

Robert Westerveld
How do I publish a Solution (.sln File) using Process in C#
I am trying to publish a .NET Core 3.1 Solution using the code below. It works fine with the variables given here. (It is a Console Application that is being debugged and a WinForm that is running this code).
string batchFilePath = @"D:\Program Files (x86)\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat";
string solutionFilePath = @"D:\Documents\Visual Studio\Visual Studio 2022\Projects\Selfmade\Selfmade.sln";
I run the following code and it will debug the solution in the default debug folder.
Process process = new Process();
var command = Environment.GetEnvironmentVariable("ComSpec");
command = @"" + command + @"";
var args = string.Format($"/S/K \" \"{batchFilePath}\" && devenv /build Debug \"{solutionFilePath}\" && exit \"");
process.StartInfo.FileName = command;
process.StartInfo.Arguments = args;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
However this code debugs the solution. I am looking for a simulair way but then to publish this solution. The only issue is that I tried using the dotnet.exe
but I cannot seem to figure out any way to publish this solution using a process.
My question is, Is there a way to use a code simulair to this but then for publishing the solution and how do you do it?
c#
process
publish
0 Answers
Your Answer