phmonte / Buildalyzer

A utility to perform design-time builds of .NET projects without having to think too hard about it.
MIT License
589 stars 92 forks source link

Make working directory used by ProcessRunner configurable #233

Closed siegfriedpammer closed 6 months ago

siegfriedpammer commented 10 months ago

Some things like detection of the current .NET version from global.json depend on the working directory of the msbuild call. Currently it is not possible to explicitly set the working directory of the msbuild invocation inside the Buildalyzer build.

Proposed API:

   public class EnvironmentOptions
    {
...
        public string WorkingDirectory { get; set; }
...
    }

(and also pass it to class BuildEnvironment of course)

and change

https://github.com/daveaglick/Buildalyzer/blob/5b732a8ce572efbba077dd08871fb609c69f94ce/src/Buildalyzer/ProjectAnalyzer.cs#L167

to

 using (ProcessRunner processRunner = new ProcessRunner(fileName, arguments, buildEnvironment.WorkingDirectory ?? Path.GetDirectoryName(ProjectFile.Path), GetEffectiveEnvironmentVariables(buildEnvironment), Manager.LoggerFactory)) 

What do you think?

Corniel commented 10 months ago

As a user of this lib, I did never needed it (yet), but only seems fair that is configurable.

daveaglick commented 10 months ago

Good suggestion, especially since a lot of MS Build functionality depends on having a correct working directory and different scenarios may change that.

daveaglick commented 6 months ago

This is now implemented and will go out with the 6.0.1 release. Thanks for the suggestion!