文件发布到FileSystem之后运行Target [英] Running Target after files are published to FileSystem

查看:51
本文介绍了文件发布到FileSystem之后运行Target的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建将所有已发布文件复制到各个文件夹的发布配置文件.不幸的是,我读到不可能直接通过publishUrl做到这一点,建议将其发布到一个文件夹中,从中复制所有文件.我设法编写了复制目标功能,但是运行目标的时间顺序是错误的. 我正在尝试通过Build> Publish Web直接从VisualStudio 2015运行发布.

I am trying to create publish profile which would copy all published files to various folders. Unfortunately I read that's not possible to do it directly through publishUrl and it's advised to publish to one folder from which to copy all the files. I managed to write the copy target functionality, but the order of when targets are run is wrong. I'm trying to run the publish directly from VisualStudio 2015, through Build > Publish Web.

这是我的发布个人资料:

Here is my publish profile:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>obj\Package\PackageTemp</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeFilesFromDeployment>Web.config;package.json;packages.config;Typescript\**;DynamicCss\**;gulpfile.js;</ExcludeFilesFromDeployment>
  </PropertyGroup>
  <Import Project="AdditionalResources.targets" />
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>AdditionalResources</CopyAllFilesToSingleFolderForPackageDependsOn>
  </PropertyGroup>
  <ItemGroup>
    <DestLocations Include="D:\PUBLISH_TEST\" />
    <DestLocations Include="D:\PUBLISH_TEST2\" />
  </ItemGroup>
  <Target Name="CopyToDeployFolders" AfterTargets="CopyAllFilesToSingleFolderForPackage" Outputs="%(DestLocations.Identity)">
    <ItemGroup>
      <PublishedFiles Include="obj\Package\PackageTemp\**\*" />
    </ItemGroup>
    <Message Importance="high" Text="FilesToCopy: @(PublishedFiles)" />
    <PropertyGroup>
      <_DeployPathIdentity>%(DestLocations.Identity)</_DeployPathIdentity>
    </PropertyGroup>
    <Copy SourceFiles="@(PublishedFiles)" DestinationFiles="@(PublishedFiles->'$(_DeployPathIdentity)%(RecursiveDir)%(Filename)%(Extension)')" />
  </Target>
</Project>

其运行顺序如下:

Build
AdditionalResources
CopyToDeployFolders
Publish folder

这是有问题的,因为尚未创建/发布我的临时文件夹.我试图将CopyToDeployFolders目标设置为重写AfterPublish,并尝试使用各种不同的AfterTarget,但是它们均无效-有时我的目标未执行,或者在发布文件夹之前仍在运行.

Which is problematic, because my temp folder is not yet created/published. I tried to make my CopyToDeployFolders Target to override AfterPublish and tried to use various different AfterTargets, but none of them worked - sometimes my target was not executed or is run still before publish folder.

我试图通过查看找出运行哪个目标 c:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v14.0 \ Web \ Microsoft.Web.Publishing.targets 如该答案所示为什么MSBuild会忽略我的BeforePublish目标?,但没有找到正确的,尝试将AfterTarget更改为其他,但结果仍然相同.

I tried to found out which target is run by looking at c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets as indicated by this answer Why does MSBuild ignore my BeforePublish target?, but didn't find the correct one, tried to changed AfterTarget to different ones, but the results are still the same.

诊断级别的输出:

2>    Target "GatherAllFilesToPublish" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets" from project "C:\MyProject\MySite\MySite.csproj" (entry point):
2>        Done building target "GatherAllFilesToPublish" in project "MySite.csproj".
2>Done building project "MySite.csproj".
2>Deleting existing files...
2>Publishing folder /...
... files being published ...
2>Web App was published successfully file:///C:/MyProject/MySite/MySite/obj/Package/PackageTemp
2>

Edit2: 添加了AdditionalResources.targets的内容

Added content of AdditionalResources.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="AdditionalResources">
    <ItemGroup>
      <AddFiles Include="$(ProjectDir)\App_Themes\**\Basic\Dynamic.css">
        <CustomPath>App_themes\</CustomPath>
      </AddFiles>
      <AddFiles Include="C:\y\SharedDLL\Clients\Web\bin\**\*.dll">
        <CustomPath>bin\</CustomPath>
      </AddFiles>
      <AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\**\ctrl_res\**\*.*" />
      <AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\js\**\*.*">
        <CustomPath>js\</CustomPath>
      </AddFiles>
      <AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\**\ClientBin\**\*.xap" />
      <AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\FileUpload\**\*.js">
        <CustomPath>js\</CustomPath>
      </AddFiles>
      <!-- Minified files should be copied last to override non-minified ones -->
      <AddFiles Include="$(ProjectDir)\MINIFIED_FILES\**\*.*" />
    </ItemGroup>
    <ItemGroup>
      <FilesForPackagingFromProject Include="%(AddFiles.Identity)">
        <DestinationRelativePath>%(AddFiles.CustomPath)%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
</Project>

推荐答案

我试图使CopyToDeployFolders Target覆盖AfterPublish,并尝试使用各种不同的AfterTarget,但是它们都不起作用

I tried to make my CopyToDeployFolders Target to override AfterPublish and tried to use various different AfterTargets, but none of them worked

在测试项目文件后,将msbuild的详细程度设置为detail.我得到的结果和你一样.然后,我发现自定义目标CopyToDeployFolders是在将文件复制到obj\Release\Package\PackageTmp 之后但在发布文件夹之前执行的.就像您获得的订单一样.

After test the project file with with msbuild verbosity set to detail. I got the same result as you. Then I found that the custom target CopyToDeployFolders was executed after copy file to obj\Release\Package\PackageTmp but before Publishing folder. Just as the order that you got.

Build
AdditionalResources
CopyToDeployFolders
Publish folder

经过进一步调查,我发现了官方答复:

After further investigation, I found a official response:

从VS发布文件系统协议后,我们当前不支持执行自定义目标.但是,如果从命令行发布,则将执行目标."

"We currently do not support executing custom targets after publish from VS for the file system protocol. If you publish from the command line the target will be executed however."

此外,就像我们在输出窗口中看到的日志一样,自定义目标CopyToDeployFolders是在复制文件到obj\Release\Package\PackageTmp之后执行的.解决方法是,可以从文件夹"obj\Release\Package\PackageTmp"而不是发布文件夹"obj\Package\PackageTemp"中复制所有文件,然后即可解决问题.

Besides, just as we saw the log in output window, the custom target CopyToDeployFolders was executed after copy file to obj\Release\Package\PackageTmp. As a workaround, you can copy all the files from the folder "obj\Release\Package\PackageTmp" rather than the publish folder "obj\Package\PackageTemp", then the problem is solved.

因此只需要将<PublishedFiles Include="obj\Package\PackageTemp\**\*" />更改为:

<ItemGroup>
  <PublishedFiles Include="obj\Debug\Package\PackageTmp\**\*" />
</ItemGroup>

这篇关于文件发布到FileSystem之后运行Target的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆