https://stackoverflow.com/questions/18963750/add-file-as-a-link-on-visual-studio-debug-vs-publish

Every time I have to link a file into an ASP.NET project as link, there is always something I forget to do, because Visual Studio is way too buggy and annoying with these. There is a bug/limitation with it so it does not copy the file into the Debug output folder, and we must change the properties of the file so that it is copied into the Publish output folder as well.

I learned this in the hard way, after a lot of research, and I created an AfterBuild target to help in making this process easier. However, there is still some manual work to do when adding the file.

Here is an example for a project I maintain. Say we want to add the file YIUCARD in the “utilities” folder of the ASP.NET project.

1) Right-click “utilities” folder on Visual Studio and select “Add -> Existing item”.

2) Select the file to add, clicking on it ONCE (do not double-click).

3) Click in the arrow next to the “Add” button and select “Add As Link”.

At the moment, this will do nothing. The file won’t be copied to any folder (Debug and Publish). It is just added to the project.

4) Right-click in the file and open Properties.

5) Change: “Build Action” to “Content” “Copy to Output Directory” to “Copy always”

At this time, the file will be copied into the Publish output folder (anywhere we define when publishing). However, when we debug locally (F5), it won’t work because the file is not copied into the local “utilities” folder on the codebase.

6) Save the changes on Visual Studio, by selecting “Save All”. This is so that the “.csproj” file is saved, as we made changes on it and we will now edit it manually.

7) Open the “.csproj” in Notepad++.

8) Add the file to the "BeforeBuild" event (here's mine):

 <Target Name="BeforeBuild">
<ItemGroup>
<UtilitiesFiles Include="..\path\to\file\REDOPXX.NEW" />
<UtilitiesFiles Include="..\path\to\file\REDFMTST" />
<UtilitiesFiles Include="..\path\to\file\JOBCARD" />
<UtilitiesFiles Include="..\path\to\file\YIUCARD" />
</ItemGroup>
<Copy SourceFiles="@(UtilitiesFiles)" DestinationFolder=".\utilities" SkipUnchangedFiles="true" />
</Target>

9) I have an "AfterBuild" event for Release mode that automatically publishes the project for me, so that the files go directly to the output folder I want:

  <Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
<PropertyGroup>
<OutputDir>..\path\to\publish\MyProject</OutputDir>
</PropertyGroup>
<Message Importance="High" Text="Output DIR: $(OutputDir)" />
<RemoveDir Directories="$(OutputDir)" ContinueOnError="true" />
<MSBuild Projects="MyProject.csproj" Properties="Configuration=$(Configuration);WebProjectOutputDir=$(OutputDir);OutDir=$(OutputDir)bin\" Targets="ResolveReferences;_CopyWebApplication" />
</Target>

10) Save the file in Notepad++ and reload it on Visual Studio.

When you build the project, the file will be copied to both Debug and Release/Publish folders!

However, I would like to know if there is any easier/intuitive way to do this.

You may say that this would be fixed by changing the Debug output folder to the same as the Release/Publish folder, so that the files would be there after the first time I published. However, please note that there is a bug with this, as well. If I use an output folder other than the "bin\", aspx files will complain that they can't find the assemblies. Even if I set "Copy to Output Directory" to "Copy Always", it will complain that "Global.asax.cs" could not be found.

Add File as a Link on Visual Studio的更多相关文章

  1. [转]Using Browser Link in Visual Studio 2013

    本文转自:https://docs.microsoft.com/en-us/aspnet/visual-studio/overview/2013/using-browser-link Browser ...

  2. Using Browser Link in Visual Studio 2013

    题记:Browser Link是VS 2013开始引入的一个强大功能,让前端代码(比如AngularJS的代码)在VS中的修改更加轻而易举. 前 端代码是运行在浏览器中,而Visual Studio通 ...

  3. Visual Studio Image Library

    The Visual Studio Image Library Visual Studio 2013   The Visual Studio Image Library contains applic ...

  4. Microsoft Visual Studio 2013 Update 5 direct download link for full ISO

    From:http://www.nickdu.com/?p=604 Visual Studio 2013 Update 5 is now released and maybe you are also ...

  5. (英文版)使用Visual Studio 2015 编写 MASM 汇编程序!

    原文地址:http://kipirvine.com/asm/gettingStartedVS2015/index.htm#CreatingProject Getting Started with MA ...

  6. Visual Studio 2019 for Mac 离线更新方法

    当你打开Visual Studio 2019 for Mac检查更新时,如果下载更新包很慢,可以尝试如下操作: 打开Finder(访达),找到~/Library/Caches/VisualStudio ...

  7. Visual Studio 2015 Update 3 正式版下载

    vs2015-update3    .NET Core 1.0  文件名 cn_visual_studio_enterprise_2015_with_update_3_x86_x64_dvd_8923 ...

  8. Visual Studio 2012 trial version

    Update: vs2012.5.iso http://download.microsoft.com/download/9/F/1/9F1DEA0F-97CC-4CC4-9B4D-0DB45B8261 ...

  9. 如何在Visual Studio中开发自己的代码生成器插件

     Visual Studio是美国微软公司开发的一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等,且所写的目标代码适用于微 ...

随机推荐

  1. Treevalue(0x03)——函数树化详细解析(下篇)

    好久不见,再一次回到 treevalue 系列.本文将基于上一篇treevalue讲解,继续对函数的树化机制进行详细解析,并且会更多的讲述其衍生特性及应用. 树化方法与类方法 首先,基于之前的树化函数 ...

  2. CF1175G

    叉姐牛逼. \(f_{k,i} = \min_{0\leq j <i}{f_{k - 1,j} + RMQ(j + 1,i) * (i - j)}\) 我们考虑在序列上分治一波. 按照\(m\) ...

  3. dotnet 将自动代码格式化机器人带入团队 GitLab 平台

    给团队带入一个 代码格式化机器人 能提升团队的幸福度,让团队的成员安心写代码,不用关注代码格式化问题,将格式代码这个粗活交给机器人去做.同时也能减少在代码审查里撕格式化问题的时间,让更多的时间投入到更 ...

  4. 【豆科基因组】绿豆Mungbean, Vigna radiata苏绿基因组预印

    目录 一.来源 二.结果 测序组装 组装评价 编码基因预测 基因功能注释 非编码RNA注释 假基因预测 重复序列注释 进化分析和分歧时间估计 全基因组复制 LTR插入时间估计 正选择基因 一.来源 H ...

  5. centos安装后的个人工具

    1.安装vim工具 yum -y install vim 安装完成后在家目录下新建一个.vimrc的配置文件.辅助vim软件功能. set number " 显示行号 set cursorl ...

  6. 【模板】负环(SPFA/Bellman-Ford)/洛谷P3385

    题目链接 https://www.luogu.com.cn/problem/P3385 题目大意 给定一个 \(n\) 个点有向点权图,求是否存在从 \(1\) 点出发能到达的负环. 题目解析 \(S ...

  7. 11 — springboot集成swagger — 更新完毕

    1.前言 理论知识滤过,自行百度百科swagger是什么 2.导入依赖 <!-- swagger所需要的依赖--> <dependency> <groupId>io ...

  8. act

    act的词源是do, 干着或干了的事情也可以叫act.抄全字典的话,抄的和看的都麻烦,在阅读中体会吧. act和action有啥区别?action: doing sth; act: n. action ...

  9. Learning Spark中文版--第四章--使用键值对(1)

      本章介绍了如何使用键值对RDD,Spark中很多操作都基于此数据类型.键值对RDD通常在聚合操作中使用,而且我们经常做一些初始的ETL(extract(提取),transform(转换)和load ...

  10. 商业爬虫学习笔记day5

    一. 发送post请求 import requests url = "" # 发送post请求 data = { } response = requests.post(url, d ...