我正在尝试创建发布配置文件,它将所有已发布的文件复制到各个文件夹。不幸的是我读到不可能直接通过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
这是有问题的,因为我的临时文件夹尚未创建/发布。我尝试使我的 CopyToDeployFolders 目标覆盖 AfterPublish 并尝试使用各种不同的 AfterTargets,但它们都不起作用 - 有时我的目标未执行或仍在发布文件夹之前运行。
我试图通过查看来找出正在运行的目标
c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets
正如这个答案所示为什么 MSBuild 忽略我的 BeforePublish 目标?,但是没有找到正确的,尝试将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>