Skip to content

Microsoft.NET.Sdk.StaticWebAssets.targets unable to publish when static web assets been removed after build phase #56755

Description

@doggy8088

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I have an ASP․NET Core Web API project. I'd like to add front-end files to the wwwroot folder during publish the project to the output directory.

  1. Assume that I have a wwwroot\.gitkeep file in the project.

  2. During dotnet build, no files will be copy to the wwwroot\ folder.

  3. I defined a Target to remove all files from wwwroot\ folder and copy all related files from another folder to the wwwroot\ folder which run before StaticWebAssetsPrepareForPublish target.

    <Target Name="NpmInstall" BeforeTargets="NpmRunBuild" Inputs="Client\package.json" Outputs="Client\node_modules\.package-lock.json">
      <Exec Command="npm install --force" Condition="'$(RestorePackagesWithLockFile)' != 'true'"
        WorkingDirectory="./Client" />
    </Target>
    <Target Name="NpmRunBuild" BeforeTargets="StaticWebAssetsPrepareForPublish" Inputs="Client\package.json" Outputs="wwwroot\index.html">
      <Exec Command="npm run build:dev" WorkingDirectory="./Client" Condition="'$(Configuration)' == 'Release' and '$(EnvironmentName)' == 'Development'" />
      <Exec Command="npm run build" WorkingDirectory="./Client" Condition="'$(Configuration)' == 'Release' and '$(EnvironmentName)' == 'Production'" />
    </Target>
  4. When I run dotnet publish, I will get an error like this: error MSB3030: Could not copy the file "D:\a\1\s\my-project\wwwroot\.gitkeep" because it was not found. [D:\a\1\s\my-project\my-project.csproj].

It seems all files existed in the build phase can't be removed during publish.

Describe the solution you'd like

I'd like to have a feature that can add/remove static files to the wwwroot folder during publish.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions