运行 文件发布到文件系统后的目标
Running Target after files are published to FileSystem
我正在尝试创建发布配置文件,它将所有已发布的文件复制到各个文件夹。不幸的是,我读到不可能直接通过 publishUrl
完成,建议发布到一个文件夹,从中复制所有文件。我设法编写了复制目标功能,但是目标 运行 的顺序是错误的。
我正在尝试 运行 通过构建 > 发布 Web 直接从 VisualStudio 2015 发布。
这是我的发布配置文件:
<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
这是有问题的,因为我的临时文件夹还没有 created/published。我试图让我的 CopyToDeployFolders 目标覆盖 AfterPublish 并尝试使用各种不同的 AfterTargets,但其中 none 有效 - 有时我的目标未执行或 运行 仍在发布文件夹之前。
我试图通过查看 运行 找出哪个目标
c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets
如这个答案所示 Why does MSBuild ignore my BeforePublish target?,但没有找到正确的,尝试将 AfterTarget 更改为不同的,但结果仍然相同。
编辑:
具有诊断级别的输出:
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>
编辑2:
添加了 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>
I tried to make my CopyToDeployFolders Target to override AfterPublish and tried to use various different AfterTargets, but none of them worked
在将 msbuild 详细信息设置为详细信息后测试项目文件。我得到了和你一样的结果。然后我发现自定义目标 CopyToDeployFolders
是在将文件复制到 obj\Release\Package\PackageTmp
但在发布文件夹 之前执行的。正如您收到的订单。
Build
AdditionalResources
CopyToDeployFolders
Publish folder
经过进一步调查,我发现了官方的回应:
"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."
此外,正如我们看到的登录输出 window,自定义目标 CopyToDeployFolders
被执行 after copy file to obj\Release\Package\PackageTmp
.作为解决方法,您可以从文件夹“obj\Release\Package\PackageTmp
”而不是发布文件夹“obj\Package\PackageTemp
”复制所有文件,然后问题就解决了。
所以只需要把<PublishedFiles Include="obj\Package\PackageTemp\**\*" />
改成:
<ItemGroup>
<PublishedFiles Include="obj\Debug\Package\PackageTmp\**\*" />
</ItemGroup>
我正在尝试创建发布配置文件,它将所有已发布的文件复制到各个文件夹。不幸的是,我读到不可能直接通过 publishUrl
完成,建议发布到一个文件夹,从中复制所有文件。我设法编写了复制目标功能,但是目标 运行 的顺序是错误的。
我正在尝试 运行 通过构建 > 发布 Web 直接从 VisualStudio 2015 发布。
这是我的发布配置文件:
<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
这是有问题的,因为我的临时文件夹还没有 created/published。我试图让我的 CopyToDeployFolders 目标覆盖 AfterPublish 并尝试使用各种不同的 AfterTargets,但其中 none 有效 - 有时我的目标未执行或 运行 仍在发布文件夹之前。
我试图通过查看 运行 找出哪个目标 c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets 如这个答案所示 Why does MSBuild ignore my BeforePublish target?,但没有找到正确的,尝试将 AfterTarget 更改为不同的,但结果仍然相同。
编辑: 具有诊断级别的输出:
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>
编辑2: 添加了 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>
I tried to make my CopyToDeployFolders Target to override AfterPublish and tried to use various different AfterTargets, but none of them worked
在将 msbuild 详细信息设置为详细信息后测试项目文件。我得到了和你一样的结果。然后我发现自定义目标 CopyToDeployFolders
是在将文件复制到 obj\Release\Package\PackageTmp
但在发布文件夹 之前执行的。正如您收到的订单。
Build
AdditionalResources
CopyToDeployFolders
Publish folder
经过进一步调查,我发现了官方的回应:
"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."
此外,正如我们看到的登录输出 window,自定义目标 CopyToDeployFolders
被执行 after copy file to obj\Release\Package\PackageTmp
.作为解决方法,您可以从文件夹“obj\Release\Package\PackageTmp
”而不是发布文件夹“obj\Package\PackageTemp
”复制所有文件,然后问题就解决了。
所以只需要把<PublishedFiles Include="obj\Package\PackageTemp\**\*" />
改成:
<ItemGroup>
<PublishedFiles Include="obj\Debug\Package\PackageTmp\**\*" />
</ItemGroup>