ASP.NET: Publishing a Web Site Does Not Publish a Resource Folder

I have a website that I am developing using ASP.NET. I am using Visual Studio 2015. When I right-click and publish a publishing site, the site is published correctly, except that my resource folder is left behind. Here's what a researcher looks like in Visual Studio

enter image description here

But after I published it, here are the files that get on Azure (access via FileZilla)

enter image description here

How do I tell Visual Studio to publish the Resources folder to the rest of the website?

+9
source share
4 answers

Likely answer

  1. Open Solution Explorer.
  2. Right-click one of the files in the resource directory.
  3. Select Properties.

Now you need to set two properties.

Build Action Content Copy to Output Directory Do not copy 

Do this with all the files you want to publish as content on a web server.

File Properties for Web Server Content

File Properties for Web Server Content

File Properties Notes

The Build Action property indicates what Visual Studio does with the file when assembling. The Build action can have one of several values:

  • No. Not what you want. The file is not part of the project output group and is not compiled during the build process. An example is a text file containing documentation, such as a Readme file that you do not want to publish to a web server.

  • Compile. Not what you want. The file is compiled into the output of the assembly. This parameter is used for code files. In other words, we compile the file and put it in the bin directory.

  • Content. Is this what you want. The file is not compiled, but is included in the content output group. For example, this parameter is the default value for a .htm web file or other type. A “content output group” is a list of files that Visual Studio will publish, while maintaining the same directory structure.

  • Embedded resource. Not what you want. This file is embedded in the output of the main project assembly in the form of a DLL or an executable file. Commonly used for resource files. In other words, it is not only in the bin directory, but also embedded in the .dll or .exe .

Copy to output directory. This property indicates the conditions under which the selected source file will be copied to the output directory. The output directory is usually bin .

see also

What are the different "build actions"? settings in Visual Studio project properties and what do they do?

MSDN file properties

+18
source

Steps to add resources for publishing (Visual Studio 2017):

1) Right-click the resource folder and select "Include in Project"

Include in project

2) Now you should see Build action: Content for image properties.

enter image description here

+1
source

If you, like me, use Visual Studio 2019, just right-click the folder and select Publish Folder Name.

+1
source

Make sure that the "Copy to output directory" property is specified in the Resources folder. Right-click the files you want to copy, select Properties, then in the Advanced section, select Copy to Output Directory. As a rule, the default value is set to "Do not copy", since most things are packaged in a DLL. Change it to “Copy if new” to force it to intercept the file. This will also create a folder structure.

-2
source

All Articles