代码之家  ›  专栏  ›  技术社区  ›  Joshua Stelten

Angular build未在Visual Studio 2017中部署到azure

  •  0
  • Joshua Stelten  · 技术社区  · 6 年前

    有了Angular5,我从来没有遇到过这个问题,然后我升级到了6,并且遇到了这个问题。无法解决,所以我创建了一个新项目并复制了所有文件。它工作了几天,现在又坏了。我没有对发布项目所涉及的任何文件做任何更改。

    这是我的csproj:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp2.2</TargetFramework>
        <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
        <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
        <IsPackable>false</IsPackable>
        <SpaRoot>ClientApp\</SpaRoot>
        <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
    
        <!-- Set this to true if you enable server-side prerendering -->
        <BuildServerSideRenderer>false</BuildServerSideRenderer>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="CsvHelper" Version="12.1.1" />
        <PackageReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
        <PackageReference Include="Sendgrid" Version="9.10.0" />
        <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
      </ItemGroup>
    
      <ItemGroup>
        <!-- Don't publish the SPA source files, but do show them in the project files list -->
        <Content Remove="$(SpaRoot)**" />
        <None Remove="$(SpaRoot)**" />
        <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
      </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>
          </ResolvedFileToPublish>
        </ItemGroup>
      </Target>
    
    </Project>
    

    路径应该是正确的,因为它在同一路径上生成角度文件,我可以在dist文件夹中找到生成文件。

    从输出文件夹中的内部版本中获取文件并用ftp手动将其上载是可行的,但当然这种行为是不需要的。

    0 回复  |  直到 6 年前
        1
  •  0
  •   Jason Smith    6 年前

    一、 也有这个问题。虽然我还没有解决方案,但我确实有一个比ftp传输更快/更容易的解决方案。在visual studio中,您可以[右键单击]dist目录并直接发布它。

    这对我很有用,是个线索。