如何防止从_bin_deployableAssemblies文件夹复制隐藏的.svn文件夹? [英] How can I prevent hidden .svn folder from being copied from the _bin_deployableAssemblies folder?

查看:163
本文介绍了如何防止从_bin_deployableAssemblies文件夹复制隐藏的.svn文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次构建后,我都使用_bin_deployableAssemblies文件夹将ASP.NET MVC程序集复制到bin文件夹中.不幸的是,MSBuild任务还复制了隐藏的.svn文件夹.

I am using the _bin_deployableAssemblies folder to copy over the ASP.NET MVC assemblies to the bin folder after each build. Unfortunately the MSBuild task also copies the hidden .svn folder.

我想在项目级别解决此问题,因此我在.csproj文件的AfterBuild目标中添加了RemoveDir任务,该任务适用于常规构建.

I want to solve this at a project level, so I have added a RemoveDir task to the AfterBuild target in the .csproj file, which works for normal builds.

<RemoveDir Directories="@(OutDir).svn" />

但是当我发布该网站时,它似乎不起作用.发布后,.svn文件夹将被复制到发布向导的目标文件夹中.而且奇怪的是,尽管执行了RemoveDir任务,它也最终位于项目的/bin文件夹中!

But it doesn't seem to work when I publish the site. After publishing the .svn folder is copied to the destination folder of the publish wizard. And strangely it also ends up in the /bin folder in the project, despite the RemoveDir task!

在目标文件C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets中,将动态创建一个项目组,以将_bin_deployableAssemblies文件夹中的所有文件包括在内:

In the targets file C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets an item group is created dynamically to include all files in the folder _bin_deployableAssemblies:

<CreateItem Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*" 
            Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
    <Output ItemName="_binDeployableAssemblies" TaskParameter="Include"/>
</CreateItem>

AfterBuild目标中使用Message任务,我可以看到该项目组包括.svn文件夹中的所有文件.

Using a Message task in the AfterBuild target I can see that this item group included all files in the .svn folder.

因此,我尝试了以下技巧来调整.AfterBuild目标中的项目组:

So I tried the following trick to adjust the item group in the .AfterBuild target:

<ItemGroup>
    <_binDeployableAssemblies Remove="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\.svn\**\*.*" />
</ItemGroup>

如果之后使用Message任务打印文件列表,则可以看到它不再包含.svn文件夹中的文件. 但是,在构建或发布时,.svn文件仍会复制到输出文件夹中!

If I print the list of files after that using a Message task I can see that it no longer includes the files in the .svn folder. But, the .svn files are still copied to the output folder when building or publishing!

似乎Publish命令首先进行常规构建,这时我们可以使用AfterBuild目标删除文件.但是随后它将文件复制到一个临时位置(在/obj文件夹中)以便发布它们.在此阶段中,它似乎将所有内容从_bin_deployableAssemblies复制到bin 再次,然后才将bin(和其他项目文件)复制到临时位置.这似乎发生在之后 AfterBuild.

It seems that the Publish command first does a regular build, at which point we can remove the files using the AfterBuild target. But then it is going to copy files to a temporary location (in the /obj folder) in order to publish them. During this phase it seems that it copies everything from _bin_deployableAssemblies over to bin again and only then copies bin (and other project files) to the temporary location. This seems to happen after AfterBuild.

因此,技巧可能是在将项目文件复制到临时文件夹之前在某个地方挂入进程.或之后,不仅如此,第二次不仅需要清除临时文件夹,还需要清除原始的bin文件夹.可以通过挂钩到许多DependsOn目标之一来实现.

So the trick might be to hook into the process somewhere before the project files are copied to the temporary folder. Or afterwards, but then not only the temporary folder needs to be cleaned, but also the original bin folder, for the second time. This may be possible by hooking into one of the many DependsOn targets.

如果没有合适的目标这样做,那么也许从某个中间项目组中删除文件可能是一个解决方案,因此它们实际上从未被复制或发布.

If there is no suitable target to do this, then perhaps removing the files from some intermediary item group could be a solution so they never actually get copied or published.

由于缺乏对发布过程的理解,我无法实现这两个可能的修复.

I have not been able to achieve either of these possible fixes due to a lack of understanding of the Publish process.

如何防止文件被复制或在复制后将其删除?我该如何针对常规版本和publish命令执行此操作?

How can I either prevent the files from being copied or remove the files after they are copied? How can I do this for both regular builds and the publish command?

推荐答案

将其添加到您的.csproj文件(或{projectName}.wpp.targets文件):

Add this to your .csproj file (or the {projectName}.wpp.targets file):

  <PropertyGroup>
    <OnAfterCopyAllFilesToSingleFolderForPackage>
      __RemoveSvnFromPackageTemp
    </OnAfterCopyAllFilesToSingleFolderForPackage>
  </PropertyGroup>

  <Target Name="__RemoveSvnFromBin" AfterTargets="_CopyBinDeployableAssemblies">
    <Message Text="Removing .SVN from BIN" Importance="normal"/>
    <RemoveDir Directories="$(OutDir).svn" />
  </Target>

  <Target Name="__RemoveSvnFromPackageTemp">
    <Message Text="Removing .SVN from PackageTempDir" Importance="normal"/>
    <RemoveDir Directories="$(_PackageTempDir)\bin\.svn" />
  </Target>

适用于构建,打包和发布!

That works for Build, Package, and Publish!

这篇关于如何防止从_bin_deployableAssemblies文件夹复制隐藏的.svn文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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