I have tried running msbuild /t:scmclean from my command prompt, it works fine , but when i try to call the same command from my c# console application using the code below namespace BuildCode { class BuildCM { public static void Main() { Process msetup = new Process(); msetup.StartInfo.FileName = "cmd.exe"; msetup.StartInfo.CreateNoWindow = true; msetup.StartInfo.RedirectStandardInput = true; msetup.StartInfo.RedirectStandardOutput = true; msetup.StartInfo.UseShellExecute = false; msetup.Start(); msetup.StandardInput.WriteLine("msbuild.exe D:\\git\\btf_pi_testrack\\Build\\Tools /t:scmclean"); msetup.StandardInput.Flush(); msetup.StandardInput.Close(); msetup.WaitForExit(); Console.WriteLine(msetup.StandardOutput.ReadToEnd()); Console.ReadKey(); } } } i get an error: C:\Users\JediAdmin\source\repos\msbuild\bin\Debug\net7.0>msbuild.exe D:\git\btf_pi_testrack\Build\Tools /t:scmclean MSBuild version 17.4.0+18d5aef85 for .NET MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file., it fails to run msbuild command for the particular directory but if i execute msbuild.exe D:\git\btf_pi_testrack\Build\Tools /t:scmclean in command prompt, it works fine. Also i did a little bit of digging for this issue and came back with Microsoft.Build.Runtime and Microsoft.Build.utilities.core for running msbuild commands from console application, however i couldn't get any code example to understabd how it does that? any idea on this as well?
Madhurima Dutta
Posts
-
Running MSBuild Commands from My C# console application. -
unable to run msbuild command from my c# console application codei have been using cliwrap for running git commands and passing the arguments. But it seems to have failed while running my msbuild command from my c# console application. What i am trying- var stdOutSetup = new StringBuilder(); var stdErrSetup = new StringBuilder(); var Setup = await Cli.Wrap("msbuild") .WithArguments("/t:scmclean && /t:setup") .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutSetup)) .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrSetup)) .ExecuteBufferedAsync(); var stdOut2 = stdOutSetup.ToString(); var stdErr2 = stdErrSetup.ToString(); Console.WriteLine("Build Commands Output :"); Console.WriteLine(stdOut2); Console.WriteLine(stdErr2); is there any possible way where i can run msbuild commands from my c# console application?
-
Running MSBuild Commands from My C# console application.i have been using cliwrap for running git commands and passing the arguments. But it seems to have failed while running my msbuild command from my c# console application. What i am trying- var stdOutSetup = new StringBuilder(); var stdErrSetup = new StringBuilder(); var Setup = await Cli.Wrap("msbuild") .WithArguments("/t:scmclean && /t:setup") .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutSetup)) .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrSetup)) .ExecuteBufferedAsync(); var stdOut2 = stdOutSetup.ToString(); var stdErr2 = stdErrSetup.ToString(); Console.WriteLine("Build Commands Output :"); Console.WriteLine(stdOut2); Console.WriteLine(stdErr2); is there any possible way where i can run msbuild commands from my c# console application?