I want to call commands such as msbuild
/dumpbin
with Environment Variables which are set in DevelopersCommandPrompt
.
I have no experience with C#, and I couldn't find a clean way to achieve this. What I thought of, was to first run Process DevelopersCommandPrompt
and read set
command output to retrieve all process environment variables and then call new Process, but this time with the dictionary of retrieved env variables.
But it turns out I cannot even get the set
command result to work.
class Program
{
static void Main(string[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo {
FileName = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\Tools\\VsDevCmd.bat",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true
};
Process devCmd = new Process();
devCmd.StartInfo = startInfo;
devCmd.Start();
devCmd.StandardInput.WriteLine("set");
devCmd.StandardInput.Flush();
devCmd.StandardInput.Close();
devCmd.WaitForExit();
Console.WriteLine(devCmd.StandardOutput.ReadToEnd());
}
}
I believe I'm doing something wrong (as when I change set
to dir
it doesn't work too). Unfortunately I have no clue what am I missing:)
Moreover if anyone has a smarter/cleaner solution for running Microsoft toolset from C# then I would love to hear it. :)
Thanks