Add File as a Link on Visual Studio
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的更多相关文章
- [转]Using Browser Link in Visual Studio 2013
本文转自:https://docs.microsoft.com/en-us/aspnet/visual-studio/overview/2013/using-browser-link Browser ...
- Using Browser Link in Visual Studio 2013
题记:Browser Link是VS 2013开始引入的一个强大功能,让前端代码(比如AngularJS的代码)在VS中的修改更加轻而易举. 前 端代码是运行在浏览器中,而Visual Studio通 ...
- Visual Studio Image Library
The Visual Studio Image Library Visual Studio 2013 The Visual Studio Image Library contains applic ...
- 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 ...
- (英文版)使用Visual Studio 2015 编写 MASM 汇编程序!
原文地址:http://kipirvine.com/asm/gettingStartedVS2015/index.htm#CreatingProject Getting Started with MA ...
- Visual Studio 2019 for Mac 离线更新方法
当你打开Visual Studio 2019 for Mac检查更新时,如果下载更新包很慢,可以尝试如下操作: 打开Finder(访达),找到~/Library/Caches/VisualStudio ...
- Visual Studio 2015 Update 3 正式版下载
vs2015-update3 .NET Core 1.0 文件名 cn_visual_studio_enterprise_2015_with_update_3_x86_x64_dvd_8923 ...
- Visual Studio 2012 trial version
Update: vs2012.5.iso http://download.microsoft.com/download/9/F/1/9F1DEA0F-97CC-4CC4-9B4D-0DB45B8261 ...
- 如何在Visual Studio中开发自己的代码生成器插件
Visual Studio是美国微软公司开发的一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码管控工具.集成开发环境(IDE)等等,且所写的目标代码适用于微 ...
随机推荐
- ceph rgw的使用,dashboard和监控
1.部署RadosGW 服务 将ceph-mgr1.ceph-mgr2 服务器部署为高可用的radosGW 服务 1.1 安装radosgw 服务 root@mgr1:~# apt install r ...
- 斗地主的综合案例实现(Map有序)
斗地主的综合案例实现(Map有序) 整体思路 代码实现 import java.util.ArrayList; import java.util.Collections; import java.ut ...
- 蓝绿部署、滚动部署、金丝雀(Canary)发布、灰度发布、A/B测试
最近看到Canary发布,一时没有反应过来是什么,一查才发现就是鼎鼎有名的金丝雀发布,发现经常一起出现的还有灰度发布.蓝绿部署.滚动部署.A/B测试,故一起学习一下这几个概念. 1. 蓝绿部署 目的: ...
- jQuery添加html绑定事件
jQuery添加html绑定事件 $("#xxx").on("click",".dev",function(){ });
- 错误笔记: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration di
亲测可用 --jack alexander@alexander-virtual-machine:~$ sudo apt-get install -y httpdE: Could not get loc ...
- Azkaban(一)【集群安装】
目录 一.下载解压 二. 配置Mysql 三. 配置Azkaban Executor 四. 配置Azkaban WebServer 一.下载解压 1.下载地址:https://github.com/a ...
- 大数据学习day15----第三阶段----scala03--------1.函数(“_”的使用, 函数和方法的区别)2. 数组和集合常用的方法(迭代器,并行集合) 3. 深度理解函数 4 练习(用java实现类似Scala函数式编程的功能(不能使用Lambda表达式))
1. 函数 函数就是一个非常灵活的运算逻辑,可以灵活的将函数传入方法中,前提是方法中接收的是类型一致的函数类型 函数式编程的好处:想要做什么就调用相应的方法(fliter.map.groupBy.so ...
- CAS你知道吗
1.比较并交换 CASDemo /** * CAS => compareAndSet * 比较并交换 */ public class CASDemo { public static void m ...
- 【Linux】【Services】【SaaS】 kubeadm安装kubernetes
1. 简介 2. 环境 2.1. OS: CentOS Linux release 7.5.1804 (Core) 2.2. Ansible: 2.6.2-1.el7 2.3. docker: 2. ...
- 【编程思想】【设计模式】【行为模式Behavioral】迭代器模式iterator
Python版 https://github.com/faif/python-patterns/blob/master/behavioral/iterator.py #!/usr/bin/env py ...