Dal*_*row 3 msbuild webdeploy npm .net-core
过去,我曾采用过这样一种策略,即后端开发人员在VisualStudio中工作,而我们的UI伙计则完全在Sublime / VSCode等工作。 app.js逻辑),然后将该前端内容包含到WebDeploy的后端程序包中。
我正在尝试在dotnet core 2.0项目中复制此代码,但是从未调用过构建前端的发布目标调用(即,您从未看到echo命令的内容,也没有npm install / build运行)...所以没有除非我以前手动运行过构建过程以从VSCode生成资源,并且发布资源已经存在于磁盘上,否则发布时将包括UI资源。就是 UI生成文件的复制效果很好(如果存在)...但VS2017从未调用npm命令来构建资源?
稍作改动,这在几个.NET 4.6+项目中都很好用。我刚刚将完全相同的逻辑复制到了Core 2.0项目中,由于某种原因,它没有按我期望的方式工作?有任何想法吗?
例如,我的ProjectDeploy.pubxml文件包含(在最后关闭的“ Project”标记之前的底部):
<!--
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>
Run Code Online (Sandbox Code Playgroud)
Okay, so I don't know if this is specific to new dotnetcore 2.0 or not, but I followed these links and got things working perfectly. Working from the inbuilt VS2017 SPA templates, I now no longer follow the approach we used in .NET 4.6 to modify the .pubxml publish profile to attempt a build/copy files.. instead the gulp/webpack build-SPA-and-copy-files-on-build logic is included in the .csproj file. Note that the benefit of this is you can BUILD your solution quickly without building the UI each time, but still bundle up all fresh UI changes on deployment. My working example follows link:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1444 次 |
| 最近记录: |