首页 > 解决方案 > 由于文件位置,发布失败

问题描述

我正在尝试使用以下命令发布 .Net Core 3.1 应用程序:

dotnet publish -r win10-x86 -c Release --self-contained=True

在运行时,它会调用npm run build --prod构建 Angular 应用程序的命令并将编译后的文件复制wwwrootaspnetcore.

在运行时它会获取一些资产并失败,因为它们位于资产文件夹中

我可以ng build --prod成功运行。

C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(237,5):错误 MSB3030:无法复制文件“C:\Users \Some Path\wwwroot\some file name.eot”,因为它没有找到。[C:\Users\some full path.csproj]

这应该在哪个C:\Users\Some Path\wwwroot\assets\some file name.eot

我的csproj文件看起来像:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
      <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
      <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
      <IsPackable>false</IsPackable>
      <SpaRoot>UI\</SpaRoot>

      <!-- Set this to true if you enable server-side prerendering -->
      <BuildServerSideRenderer>false</BuildServerSideRenderer>
  </PropertyGroup>
    
    <!-- <PropertyGroup Condition="'$(Configuration)' == 'Release'"> -->
    <!--     <PostBuildEvent>npm run production</PostBuildEvent> -->
    <!-- </PropertyGroup> -->

  <ItemGroup>
      <Content Remove="$(UI)**" />
      <None Remove="$(UI)**" />
      <None Include="$(UI)**" Exclude="$(UI)node_modules\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.8" />
    <PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Collections" Version="4.3.0" />
    <PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
    <PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
    <PackageReference Include="System.Management" Version="4.7.0" />
    <PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
    <PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
    <PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\some project.csproj" />
    <ProjectReference Include="..\..\some project.Client.csproj" />
    <ProjectReference Include="..\..\some project.Models.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

    <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
        <!-- Ensure Node.js is installed -->
        <Exec Command="node --version" ContinueOnError="true">
            <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
        </Exec>
        <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
        <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    </Target>

    <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
        <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
        <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

        <!-- Include the newly-built files in the publish output -->
        <ItemGroup>
            <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
            <DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
            <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
                <RelativePath>%(DistFiles.Identity)</RelativePath>
                <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
                <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
            </ResolvedFileToPublish>
        </ItemGroup>
    </Target>

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)' == 'Release'">
    <Exec Command="npm run production" />
  </Target>


</Project>

那么关于我的问题,我在哪里更改它以查看这些资产的正确文件夹?

标签: .net-coresingle-page-applicationangular9

解决方案


我能够弄清楚这一点。问题是这样的:

<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />

应该

<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod" />

推荐阅读