I'm adding a Nuke build project to my solution.
I need to create a target which copies the compiled files to a custom folder. You can think of it as a sort of deploy.
How do I get the output folder of a specific project?
For example, if the project is called "MyProject" and it's in the C:\git\test\MyProject folder, I need to get the output path based on the current configuration and platform, such as C:\git\test\MyProject\bin\x64\Release.
I tried this one, but it gives me the first value of the OutputPath property, not the one for the current configuration and platform:
readonly Configuration Configuration = Configuration.Release;
readonly MSBuildTargetPlatform Platform = MSBuildTargetPlatform.x64;
// ...
Target LocalDeploy => _ => _
.DependsOn(Compile)
.Executes(() =>
{
var myProject = Solution.GetProject("MyProject");
var outputPath = myProject.GetProperty("OutputPath"); // this returns bin\Debug
var fullOutputPath = myProject.Directory / outputPath;
CopyDirectoryRecursively(fullOutputPath, @"C:\DeployPath");
});
I also tried this way, which honor the Configuration but not the Platform:
var myProject = Solution.GetProject("MyProject");
var myMSBuildProject = visionTools3Project.GetMSBuildProject(Configuration);
var outputPath = myProject.GetProperty("OutputPath"); // this returns bin\Release
var fullOutputPath = myProject.Directory / outputPath;
CopyDirectoryRecursively(fullOutputPath, @"C:\DeployPath");
This is the workaround I finally used.
readonly Configuration Configuration;
readonly MSBuildTargetPlatform Platform;
//...
Target Example => _ => _
.DependsOn(Compile)
.Executes(() =>
{
var project = Solution.GetProject("MyProject");
var outputPath = GetOutputPath(project);
// ...
});
private AbsolutePath GetOutputPath(Project project)
{
var relativeOutputPath = (RelativePath)"bin";
if (Platform == MSBuildTargetPlatform.x64)
{
relativeOutputPath = relativeOutputPath / "x64";
}
relativeOutputPath = relativeOutputPath / Configuration;
return project.Directory / relativeOutputPath;
}
It's quite hardcodeded and it doesn't take the the default output path of netstandard projects into account. Hopefully it can be useful as starting point for those who are trying to solve the same issue.
A simple way to do this is to construct the path to your output folder like this:
AbsolutePath OutputDirectory = RootDirectory / "MyProjectFolder" / "bin" / Configuration / "netstandard2.0";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With