对npm生成的DotNet Core 2.0 WebDeploy调用在发布上不起作用

对npm生成的DotNet Core 2.0 WebDeploy调用在发布上不起作用,npm,msbuild,.net-core,webdeploy,Npm,Msbuild,.net Core,Webdeploy,我过去使用过一种策略,即我们的后端开发人员在VisualStudio中工作,我们的UI人员在Sublime/VSCode中工作。在VS2017网站发布期间,我使用发布目标先运行npm安装,然后运行npm构建(捆绑我们的app.js逻辑),然后将前端内容包含到WebDeploy的后端包中 我试图在dotnet core 2.0项目中复制这一点,但从未调用用于构建前端的发布目标调用(即,您从未看到echo命令内容,也没有运行npm安装/构建)。。。因此,发布时不包括UI资源,除非我以前手动运行构建过

我过去使用过一种策略,即我们的后端开发人员在VisualStudio中工作,我们的UI人员在Sublime/VSCode中工作。在VS2017网站发布期间,我使用发布目标先运行npm安装,然后运行npm构建(捆绑我们的app.js逻辑),然后将前端内容包含到WebDeploy的后端包中

我试图在dotnet core 2.0项目中复制这一点,但从未调用用于构建前端的发布目标调用(即,您从未看到echo命令内容,也没有运行npm安装/构建)。。。因此,发布时不包括UI资源,除非我以前手动运行构建过程从VSCode生成UI资源,并且它们已经存在于磁盘上。也就是说,复制UI生成的文件非常有效(如果存在的话)。。。但是VS2017从未调用npm命令来构建资源

虽然这是一个微妙的变化,但它在几个.NET4.6+项目中非常有效。我刚刚将完全相同的逻辑复制到一个核心2.0项目中,出于某种原因,它没有按照我预期的方式工作?有什么想法吗

例如,my ProjectDeploy.pubxml文件包含(在最终结束“Project”标记之前的底部):


..\..\src应用程序
wwwroot\%(递归目录)%(文件名)%(扩展名)
自定义文件;
自定义文件;

好的,所以我不知道这是否是新的dotnetcore 2.0所特有的,但我遵循了这些链接,使事情完美地运行起来。从内置的VS2017 SPA模板开始,我现在不再采用.NET 4.6中使用的方法来修改.pubxml发布配置文件以尝试生成/复制文件。。相反,gulp/webpack构建SPA和复制构建逻辑上的文件包含在.csproj文件中。请注意,这样做的好处是您可以快速构建解决方案,而无需每次构建UI,但仍然可以在部署时捆绑所有新的UI更改。我的工作示例如下:


..\..\src应用程序

web项目(而不是发布文件)中的预构建事件会有帮助吗?我有意避免在构建过程中编译UI资源,因为这会大大降低后端开发周期。。我希望UI资源只在发布期间生成和绑定。
  <!-- 
  make sure that we BUILD the UI *before* we copy the files to the package
  See: http://byalexblog.net/using-msbuild-to-deploy-composite-web-application
  See: http://www.codecadwallader.com/2015/03/15/integrating-gulp-into-your-tfs-builds-and-web-deploy/
  -->
  <PropertyGroup>
    <!-- relative path back out of 'current' folder to outside location of the UI files -->
    <FrontEndLocalPath>..\..\src-app</FrontEndLocalPath>
  </PropertyGroup>
  <!-- 
  Build the mobile web app assets , ensuring that all packages are installed and up to date
  -->
  <Target Name="BuildFrontEnd">
    <Exec Command="echo Got Here also Dale" />
    <!-- requires that NPM be installed in environment variables, which we will assume rather than use the NPM env variable above -->
    <!-- call npm install -->
    <exec command="npm install" WorkingDirectory="$(FrontEndLocalPath)" />
    <!-- Run npm run build to populate the www folder with your latest minified production build. -->
    <exec command="npm run build" WorkingDirectory="$(FrontEndLocalPath)" />
  </Target>
  <!--
  On each package and/or deploy (because they are different), we want to ensure that we bundle up all the Angular dist code and include that as part of the package / deployment.
  See: https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-extra-files
  -->
  <Target Name="CustomCollectFiles" DependsOnTargets="BuildFrontEnd">
    <Exec Command="echo Got Here Dale" />
    <ItemGroup>
      <_CustomFiles Include="$(FrontEndLocalPath)\www\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>CustomCollectFiles;</CopyAllFilesToSingleFolderForPackageDependsOn>
    <CopyAllFilesToSingleFolderForMsdeployDependsOn>CustomCollectFiles;</CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>
<PropertyGroup>
    <!-- 
    relative path back out of 'current' folder to outside location of the 
    custom single page app UI files (and any other paths we require)
    -->
    <FrontEndLocalPath>..\..\src-app</FrontEndLocalPath>
  </PropertyGroup>

  <Target Name="DebugBuildSPA" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
    <!-- 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." />

    <!-- 
    In development, the dist files won't exist on the first run or when cloning to
    a different machine, so rebuild them if not already present. 
    -->
    <Message Importance="high" Text="Performing first-run Webpack build..." />
    <exec command="npm install" WorkingDirectory="$(FrontEndLocalPath)" />
    <exec command="npm run build" WorkingDirectory="$(FrontEndLocalPath)" />
  </Target>

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
    <!-- Build our single page application content -->
    <exec command="npm install" WorkingDirectory="$(FrontEndLocalPath)" />
    <exec command="npm run build" WorkingDirectory="$(FrontEndLocalPath)" />
    <ItemGroup>
      <Dist Include="$(FrontEndLocalPath)\www\**;" />
    </ItemGroup>
    <Copy SourceFiles="@(Dist)" DestinationFolder="$(PublishDir)\wwwroot\%(RecursiveDir)" SkipUnchangedFiles="true" />
  </Target>