You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Nuke发布.NET项目时ClientApp文件夹未被包含的问题

Nuke自动化发布无法包含ClientApp文件夹问题

项目结构

MyApp
│
├── MyApp.Client
│
└── MyApp.Server

我希望通过命令nuke --Environment Staging --Publish true实现发布流程自动化。手动右键项目并使用「Publish-Staging」配置文件发布时一切正常,但通过Nuke命令执行时出现问题:

我已在MyApp.Server.csproj中添加以下配置,确保发布时包含ClientApp文件夹:

<ItemGroup>
    <Content Include="ClientApp\**">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemGroup>

其中MyApp.Client是Angular前端项目,编译后产物会输出到MyApp.Server/ClientApp/dist目录,该目录下文件均正常生成,但通过Nuke发布后,ClientApp文件夹并未被包含进发布包,且无任何报错信息。

我的Nuke脚本

class Build : NukeBuild
{
    public static int Main() => Execute<Build>(x => x.Compile);

    [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
    readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

    [Parameter("Environment")]
    readonly string Environment;

    [Parameter("Publish")]
    readonly bool Publish = false;

    [Parameter("Path to the Angular project")]
    readonly string AngularProjectPath = "MyApp.Client";

    [Parameter("Path to the .NET Core project")]
    readonly string DotNetProjectPath = "MyApp.Server/MyApp.Server.csproj";

    Target Clean => _ => _
        .Executes(() =>
        {
            Console.WriteLine("Cleaning directories...");
            // Clean Angular build output directory
            if (Directory.Exists("MyApp.Server/ClientApp"))
            {
                Directory.Delete("MyApp.Server/ClientApp", true);
            }
            // Clean .NET build output directory
            if (Directory.Exists("MyApp.Server/bin"))
            {
                Directory.Delete("MyApp.Server/bin", true);
            }
            if (Directory.Exists("MyApp.Server/obj"))
            {
                Directory.Delete("MyApp.Server/obj", true);
            }
        });

    Target Restore => _ => _
        .DependsOn(Clean)
        .Executes(() =>
        {
            Console.WriteLine("Restoring dependencies...");
            // Restore .NET Core project dependencies
            DotNetRestore(s => s.SetProjectFile(DotNetProjectPath));

            // Restore Angular dependencies
            ProcessTasks.StartProcess("npm", "install", AngularProjectPath)
                .AssertZeroExitCode();
        });

    Target BuildAngular => _ => _
        .DependsOn(Restore)
        .Executes(() =>
        {
            Console.WriteLine("Building Angular project...");
            string env = Environment.ToLower(); // angular.json configurations are lower case.
            ProcessTasks.StartProcess("ng", $"build --configuration={env}", AngularProjectPath)
                .AssertZeroExitCode();
        });

    Target BuildDotNet => _ => _
        .DependsOn(BuildAngular)
        .OnlyWhenDynamic(() => !Publish)
        .Executes(() =>
        {
            // Build .NET Core project with the specified configuration
            Console.WriteLine("Building .NET Core project...");
            DotNetBuild(s => s
                .SetProjectFile(DotNetProjectPath)
                .SetConfiguration(Configuration)
                .SetProperty("Environment", Environment));
        });

    Target PublishMsBuild => _ => _
        .DependsOn(BuildDotNet)
        .OnlyWhenDynamic(() => Publish)
        .Executes(() =>
     {
         var publishProfile = $"Publish-{Environment}";

         MSBuildTasks.MSBuild(s => s
                     .SetProjectFile(DotNetProjectPath)
                     .SetConfiguration(Configuration)
                     .SetProperty("PublishProfile", publishProfile)
                     .SetTargets("Publish")
                 );
     });
}

尝试过的其他方案

我曾将发布逻辑改为使用DotNetPublish,结果完全相同:

Target PublishDotNet => _ => _
    .DependsOn(BuildDotNet)
    .OnlyWhenDynamic(() => Publish)
    .Executes(() =>
    {
        // Publish .NET Core project with the specified profile
        Console.WriteLine("Publishing .NET Core project...");
        var publishProfile = $"Publish-{Environment}";
        DotNetPublish(s => s
            .SetProject(DotNetProjectPath)
            .SetConfiguration(Configuration)
            .SetPublishProfile(publishProfile));
    });

我还尝试过执行MSBuild脚本的命令行等价指令,依旧无法将ClientApp文件夹包含至发布包,仅手动发布可正常工作。目前甚至出现无任何内容被发布的情况,我不清楚脚本哪里出了问题。

内容的提问来源于stack exchange,提问作者user25604856

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 01:00:08