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. 制作nc文件(Matlab)

    首先看一个nc文件中包含哪些部分,例如一个标准的 FVCOM 输入文件 wind.nc: netcdf wind { dimensions: nele = 36858 ; node = 18718 ; ...

  2. Yii2 源码分析 入口文件执行流程

    Yii2 源码分析  入口文件执行流程 1. 入口文件:web/index.php,第12行.(new yii\web\Application($config)->run()) 入口文件主要做4 ...

  3. Docker Nginx-Proxy 容器Nginx Proxy反向代理

    Docker Nginx-Proxy 容器Nginx Proxy反向代理   简单介绍 Docker容器的自动Nginx反向代理   dockerhub地址 https://hub.docker.co ...

  4. Oracle-判断一个表的一列是否在另一张表的一列存在

    select * from A where exists(select 1 from B where A.a = B.b)  

  5. svn简单上传下载文件命令

    上传命令: svn import 本地文件或目录 远程服务端目录 --username '用户名' --password '密码' -m '添加描述(可为空)' 下载命令: svn export 远程 ...

  6. tensorboard No dashboards are active for the current data set.

    修改一下启动命令时的路径 位置示例: 命令为   E:\PYTHON_PROJECT\testTF\inceptionV1_net\log>tensorboard --logdir=TEC4FN ...

  7. Java 数据类型转化

    目录 Java类型转化 基本数据类型自动类型转换 自动类型提升 强制类型转换 - 自动类型提升的逆运算 int与long int类型与String类型 int类型转换成String类型 方法1:+ 拼 ...

  8. [PE结构]导出表结构浅析

    导出函数的总数-->以导出函数序号最大的减最小的+1,但导出函数序号是可自定义的,所以NumbersOfFunctions是不准确的 1.根据函数名称找,函数名称表->对应索引函数序号表中 ...

  9. Gradle安装与配置

    一.Gradle安装 1.Gradle安装 (1)先安装JDK/JRE (2)Gradle下载官网 Gradle官网 (3)解压安装包到想安装到的目录.如D:\java\gradle-5.2.1 (4 ...

  10. Shell学习(十)——du、df命令

    一.du 命令 1.命令格式: du [选项][文件] 2.命令功能: 显示每个文件和目录的磁盘使用空间. 3.命令参数: -a或-all 显示目录中个别文件的大小. -b或-bytes 显示目录或文 ...