我试图创建发布配置文件,将所有发布的文件复制到各种文件夹。不幸的是,我读了这是不可能的,直接通过publishUrl
,它建议发布到一个文件夹,从中复制所有的文件。我设法编写了复制目标功能,但目标运行的顺序是错误的。 我试图通过Build> Publish 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
这是有问题的,因为尚未创建我的temp文件夹/发表。我试图让我的CopyToDeployFolders目标覆盖AfterPublish,并尝试使用各种不同的AfterTargets,但都没有工作 - 有时我的目标没有执行,或者在发布文件夹之前仍然运行。
我试图找出其目标是通过观察 运行C:\ Program Files文件(x86)的\的MSBuild \微软\ VisualStudio的\ v14.0 \网络\ 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>
EDIT2: 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>
运行,它会显示所有的目标,然后随便挑一个合适的具有AfterTargets使用。 – stijn
@stijn试过,但文件开始发布时没有目标。更新我的问题而不输出。 – CrudaLilium
@CrudaLilium,我用你的发布配置文件创建了一个示例,测试后发现发布后我执行了目标CopyToDeployFolders(我评论目标AdditionalResources,因为我没有AdditionalResources.targets文件)。所以你会介意通过onedrive与我们分享AdditionalResources.targets文件或者测试样例,在这里分享链接,这样我们就可以重现这个问题。 –