English 中文(简体)
将视觉工作室中的文件复制链接到位置
原标题:copy linked files in visual studio to a location

我在我的视觉工作室解决方案中设置了一个项目, 包含许多链接的文件。 这些是内容文件 。

当我建造这个项目时,我想把链接的文件复制到另一个地方。这有可能吗? 我怎样才能做到这一点?

问题回答

For anybody stumbling on this page like myself, further to 5arx post, I implemented an MSBuild target that copies all linked content files to their "virtual" locations (the directory where you placed the link in Visual Studio): http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx

多年来,我一直使用,但用视觉工作室2022/.NET 6,它根本行不通。视觉工作室似乎不再“看到”任何作为链接添加的内容文件,而副本基本上什么都不用。

下面是我现在的工作。在我的例子中,我有一大堆联署材料, 包含在wwwroot/common/js的多个项目中。 我在我的 CSPROJ 档案中添加以下内容:

<ItemGroup>
  <!-- Adds the files as links in the Solution Explorer.
       When you double-click, it opens the original file. -->
  <Content Include="....Common***.js">
    <Link>wwwrootCommon\%(RecursiveDir)%(FileName)%(Extension)</Link>
  </Content>

   <!-- Picked up by the Copy below.  Using "Content"
        with "Link" adds external files as links.  But a custom
        name is needed for use with Copy. -->
  <CommonJs Include="....Common***.js" />

  <!-- Tells Visual Studio to ignore any actual files at this location.
       I found that if I didn t do this, Visual Studio sees the copied
       file instead of the linked file.  This tells Visual Studio to
       ignore the copied file so that when I double-click it in
       Solution Explorer, it opens the original copy. -->
  <Content Remove="wwwrootCommon**" />
</ItemGroup>

<Target Name="CopyCommonJs" BeforeTargets="Build">
  <Copy SourceFiles="@(CommonJs)"
        DestinationFiles="wwwrootCommon\%(RecursiveDir)%(Filename)%(Extension)"
        SkipUnchangedFiles="true"
        OverwriteReadOnlyFiles="true" />
</Target>

整个方法行之有效,我现在理解了所有部分,但我更喜欢旧的方法,希望它仍然有效。 如果有人找到更优雅的东西,请告诉我。

您可以使用“ http://msdn.microsoft.com/ en- us/library/ 0k6kkbsd” rel = “ no follow” >MSBruild 。 具体来说, 其< a href=> http://msdn. microsoft. com/ en- us/library/3e54c37h.aspx" rel=“ nofolpol” > Copy 文件 任务 :

似乎只是简单地添加:

<CopyToOutputDirectory>Always</CopyToOutputDirectory>

与视觉工作室 2017 csproj 工程文件中的链接文件项相关联, 将使链接文件被复制到建设中的输出目录, 不论您是否宣布构建动作为无或内容 。

举例来说,这两个工作...

<None Include="..configurationShared.OctopusDeploy.config">
  <Link>Shared.OctopusDeploy.config</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

<Content Include="..configurationShared.OctopusDeploy.config">
  <Link>Shared.OctopusDeploy.config</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签