JosephStyons
JosephStyons

Reputation: 58685

How can I get output file names after a C# MSBuild completes?

I am using BuildManager.DefaultBuildManager.Build() to build a visual studio solution which contains many projects. My code looks a lot like this.

Once the build completes, I'd like to copy the output (DLLs in my case) to a target folder.

But I don't see any way to retrieve the file names of the build output from the BuildResult.

I can scan the SLN file and then infer the output locations. But that will be error-prone and tedious.

Build() returns a BuildResult. As far as I can tell, BuildResult does not contain the actual output file names.

How can I get the output file names after a build completes?

Upvotes: 0

Views: 1079

Answers (1)

Xiaoy312
Xiaoy312

Reputation: 14477

You could provide an output path for the build. Just clear the folder before you build and work with the newly generated files.

var solutionPath = "...";
var outputPath = "...";

var pc = new ProjectCollection();
var properties = new Dictionary<string, string>();
properties.Add("OutputPath", outputPath);

var request = new BuildRequestData(solutionPath, properties, null, new string[] { "Build" }, null);
var result = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), request);

// do stuffs with the dlls
var libraries = Directory.GetFiles(outputPath, "*.dll");

Upvotes: 2

Related Questions