Visual Studio的"新增为纽带"在调试时不工作 [英] Visual Studio "Add As Link" not working while debugging

查看:269
本文介绍了Visual Studio的"新增为纽带"在调试时不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2010来维护所有安置在部署时在同一网站上大约40不同的Web应用程序。这些项目都在同一个解决方案,但住在不同的项目,因为他们每一个做的非常不同的事情。

I use Visual Studio 2010 to maintain around 40 different web applications that are all housed on the same website upon deployment. These projects are in the same solution but housed in different projects as they each do very different things.

我想通过添加链接选项共享的各种项目中的CSS / JS文件,这样我可以一次更新CSS或js文件并自动更新反映在各个项目无需构建并重新部署每个项目。

I'm trying to share css/js files among the various projects via the "Add As Link" option that way I can update the css or js files once and automatically have the updates reflected in the various projects without having to build and redeploy each project.

这是我遇到的问题是,当我试图在我的电脑用于调试的那些链接的文件没有工作在本地运行的项目。我越来越找不到文件。

The issue that I am having is when I am trying to run a project locally on my PC for debugging purposes those linked files aren't working. I'm getting a file not found.

我的思想:我认为这是因为文件夹结构在本地运行应用程序时是不同的。我很好奇,如果有复制在调试模式建设,只有当文件到该项目,并相应地调整相对URL,这样我就可以发布到我们的Web服务器之前正确测试应用程序的方式。

My Thought: I assume that this because the folder structure is different when running the applications locally. I'm curious if there is a way to copy the files to the project only when building in debug mode and adjust the relative URLs accordingly so that I will be able to properly test the application before publishing to our web server.

谢谢,

推荐答案

解决这个问题的复制内容文件(如JS,CSS或其它)这是每个制作过程中添加的链接。有几种方法可以做到这一点。我可以建议使用可以通过不同的Web应用程序项目重用的MSBuild目标。

The solution to this problem is copying content files (like js, css or others) which are added as link during each build. There are several ways to do this. I can advice to use MSBuild target which can be reused by different web application projects.

所以,你可以(通过命名它WebApplication.Extension.targets为例)具有以下内容创建以下文件:

So you can create the following file (for example by naming it WebApplication.Extension.targets) with the following content:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <!-- Override the default target dependencies to -->
    <!-- include the new CopyLinkedContentFiles target. -->
    <PropertyGroup>
        <BuildDependsOn>
            CopyLinkedContentFiles;
            $(BuildDependsOn);
        </BuildDependsOn>
    </PropertyGroup>

    <!--
    ============================================================
    CopyLinkedContentFiles

    A new target to copy any linked content files into the 
    web application output folder.

    NOTE: This is necessary even when '$(OutDir)' has not been redirected.
    ============================================================
    -->
    <Target Name="CopyLinkedContentFiles">
        <!-- Remove any old copies of the files -->
        <Delete Condition=" '%(Content.Link)' != '' AND Exists('$(WebProjectOutputDir)\%(Content.Link)') "
                Files="$(WebProjectOutputDir)\%(Content.Link)" />
        <!-- Copy linked content files recursively to the project folder -->
        <Copy Condition=" '%(Content.Link)' != '' " SourceFiles="%(Content.Identity)"
              DestinationFiles="$(WebProjectOutputDir)\%(Content.Link)" />
    </Target>
</Project>

,然后通过把下面的行.csproj的文件,这个目标添加到您的Web应用程序项目:

And then add this target to you web application project by placing the following line in .csproj file:

<Import Project="$(MSBuildProjectDirectory)[RelativePathToFile]\WebApplication.Extension.targets" />

基本上你可以在以后的文件.csproj的加入这一行下列操作之一:

Basically you can add this line in .csproj file after the following one:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

在这个问题与内容的文件添加为链接应该解决的问题。

After this problem with content files added as link should be resolved.

编辑:
要执行只有当调试配置是内置的MSBUILD你必须指定条件的元素能力以下逻辑。

To execute the following logic only when debug configuration is built in MSBUILD you have ability to specify Condition element.

例如汇入指定的目标只为调试配置可以更新import语句如下:

For example to import specified target only for debug configuration you can update import statement to the following:

<Import Project="$(MSBuildProjectDirectory)[RelativePathToFile]\WebApplication.Extension.targets" Condition=" '$(Configuration)' == 'Debug' "/>

EDIT2:

要解决这个问题,前一段时间我创建了一个<一个href=\"https://www.nuget.org/packages/MSBuild.WebApplication.CopyContentLinkedFiles/\">MSBuild.WebApplication.CopyContentLinkedFiles'的NuGet包。这个包增加了其复制所有内容的文件添加为纽带构建过程中,项目文件夹中的MSBuild目标。

To overcome this problem some time ago I created a 'MSBuild.WebApplication.CopyContentLinkedFiles' nuget package. This package adds MsBuild target which copies all content files added as link to project folder during build.

这篇关于Visual Studio的&quot;新增为纽带&QUOT;在调试时不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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