Need help moving MSBuild to Nuke

190 Views Asked by At

I'm trying to replace MSBuild with nuke, but I'm having trouble doing so. The first thing that I tried to do is setting the intermediate output paths and whatnot to another folder. I have previously done this in MSBuild by using a props file that defines BaseOutputPath, OutputPath, BaseIntermediateOutputPath, IntermediateOutputPath to some sane values in the build folder. So what I did is I defined functions for getting these values in my nuke build script:

    const string DefaultBuildOutputFolderName = "build_folder";
    [Parameter($"Absolute path where to output kari built things. Default is \"{DefaultBuildOutputFolderName}\"")]
    readonly AbsolutePath KariBuildPath = null;

    AbsolutePath SourceDirectory => RootDirectory / "source";
    AbsolutePath BuildOutputDirectory => KariBuildPath ?? (RootDirectory / DefaultBuildOutputFolderName);
    AbsolutePath BinOutputDirectory => BuildOutputDirectory / "bin";
    AbsolutePath ObjOutputDirectory => BuildOutputDirectory / "obj";
    AbsolutePath PackageOutputDirectory => BuildOutputDirectory / ".nupkg";
    
    AbsolutePath GetProjectBaseOutputPath(string projectName) => BinOutputDirectory / projectName;
    AbsolutePath GetProjectOutputPath(string projectName, string configuration) => GetProjectBaseOutputPath(projectName) / configuration;
    AbsolutePath GetBaseIntermediateOutputPath(string projectName) => ObjOutputDirectory / projectName;
    AbsolutePath GetIntermediateOutputPath(string projectName, string configuration) => GetBaseIntermediateOutputPath(projectName) / configuration;
    AbsolutePath GetPackageOutputPath(string projectName, string configuration) => PackageOutputDirectory / projectName / configuration;

Then I'm just setting individual properties, which also have to have a trailing slash

    DotNetPublishSettings SetSaneDefaults(DotNetPublishSettings settings, string projectName)
    {
        return settings
            .SetConfiguration(Configuration)
            .SetFramework("net6.0")
            .SetProperty("BaseOutputPath", GetProjectBaseOutputPath(projectName) + System.IO.Path.DirectorySeparatorChar)
            .SetProperty("OutputPath", GetProjectOutputPath(projectName, Configuration) + System.IO.Path.DirectorySeparatorChar)
            .SetProperty("BaseIntermediateOutputPath", GetBaseIntermediateOutputPath(projectName) + System.IO.Path.DirectorySeparatorChar)
            .SetProperty("IntermediateOutputPath", GetIntermediateOutputPath(projectName, Configuration) + System.IO.Path.DirectorySeparatorChar)
            .SetProperty("PackageOutputPath", GetPackageOutputPath(projectName, Configuration) + System.IO.Path.DirectorySeparatorChar)
            .SetProperty("AssemblyName", projectName);
    }

What's the right way to do it? Also, how would it resolve the dependencies if I'm setting these properties per project? Is it possible for nuke to handle the whole build process and not delegate to msbuild? MSBuild sucks and will involve to some extent configuration duplication Say, I want to build a project. Do I have to respecify its dependencies and manually invoke a build for each? Like I'm completely lost how to do this I've read through the docs but practically it's not clear at all how to do it Is it possible to specify all configuration outside project files and have the project files and the solution file get autogenerated?

The project is by this link

0

There are 0 best solutions below