ASP.NET: Publishing Website doesn't publish Resources folder - c#

I have a website that I'm developing with ASP.NET. I'm using Visual Studio 2015. When I right-click and hit publish website the site publishes correctly except that my resources folder gets left behind. Heres what the solution explorer looks like in Visual Studio
But after I publish it here are the files that get put on Azure (accessed via FileZilla)
How do I tell Visual Studio to publish the Resources folder with the rest of the website?

Likely Answer
Open the Solution Explorer.
Right click one of the files in the Resources directory.
Choose Properties.
You now need to set two properties.
Build Action Content
Copy to Output Directory Do not copy
Do this to all the files that you would like to publish as content to the web server.
File Properties for Web Server Content
Remarks on File Properties
The Build Action property indicates what Visual Studio does with a file when a build is executed. Build Action can have one of several values:
None. Not what you want. The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file, that you do not want to publish to the web server.
Compile. Not what you want. The file is compiled into the build output. This setting is used for code files. In other words, we compile the file and the stick it into the bin directory.
Content. This is what you want. The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file. The "Content output group" is a list of files that Visual Studio will publish while also maintaining the same directory structure.
Embedded Resource. Not what you want. This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files. In other words, it not only goes into the bin directory but is also embedded within a .dll or .exe file.
Copy to Output Directory. This property specifies the conditions under which the selected source file will be copied to the output directory. The output directory is normally the bin.
See Also
What are the various "Build action" settings in Visual Studio project properties and what do they do?
File Properties on MSDN

If like me you are using Visual studio 2019, just right-click on the folder and select publish "name of the folder"

Steps to add resources to be published (Visual Studio 2017):
1) Right click the resources folder and select "Include In Project"
2) Now you should see Build Action: Content on the properties for the images.

Make sure the contents of your Resources folder have the proper "Copy to Output Directory" property. Right click the files you want to copy over, select Properties, then in the Advanced section look at the value under Copy to Output Directory. Generally this is set to "Do not copy" by default since most things get packaged up in the .dll. Change it to "Copy if newer" to get it to bring over the file. It'll bring over the folder structure as well.

Related

WPF Publish - include folders

I have a WPF project that is now finished, and I want to publish the app into an installer that other people can use.
When I publish the project, the project compiles into setup.exe, but on install the folders that I have do not get included.
I've been reading the guides, and made sure to include the files inside the folders as Content or a Resource. I've also made sure they are always copied. When some of my files are copied, they have a .deploy extension, and I need it to be an .xml in order for some function to read them. Images that I have in the app load fine however.
What do I need to do to have my custom files be EXACTlY as they are, xml as xml, txt as txt and so on. Also I have some empty folders, like this TempCF that I use at some point. Do i need to create it via code?
If you go to Project->Properties->Publish->Install Mode and Settings->Options->Deployment in Visual Studio, there is a "Use ".deploy" file extension" option that you can untick to get rid of the .deploy extension being added to your published files:
Empty project folders are not included in the output. Either put a dummy content file in them or create the folder dynamically as needed during runtime.
# Nikola L.
You could try to use the following methods to add the files in your program to the installation package so that you can have the files you need in your installation path. If I misunderstood your question, please let me know.
The steps are as follows:
1.Right-click on the Setup project and select View -> File System
2.In the File System page, right-click the Application Folder (File System on target Machine) and select Add->Folder(named User's Application Data ) -> Fileā€¦-> find the file under your project and select the file you need.
Such as:
3.Right-click the Setup project.
Install your setup package.
You can find the files you added in your installation path.
The result is like the picture below:

WPF - How can I generate a file inside the directory where the program is installed?

I'm trying to create a WPF application to do some of the time consuming QA tasks easier. Now I ran into problem of creating a file that would be used for configuration of some operation via ssh. This file will contain default configuration, however it might be updated by the user with new values.
I changed the properties of a file to "Build Action - Content" and "Copy to Output Directory - Always" however when I publish and install the application the file is not in the directory.
How can I make the file appear in the output directory and be available for some changes?
The published files get a .deploy extension by default. This is a setting that can be changed under Project->Publish->Options->Deployment in Visual Studio.
If you uncheck the Use ".deploy" file extension option and re-publish, you should see and be able to use the content file in the Application Files/app directory of the output folder.

User manual text file not available in the exe version

I've just made my program an exe via publish in visual studio. In that i included a usermanual.txt and a aboutus.txt file which are in bin>debug folder. After i published the program and run it. Those files are not viewing saying cannot find the file. How can i fix this
Make sure your files are included in Solution Explorer. If not, add them (Right click on project -> Add -> Existing item... then select them from disk).
This way your manuals will be part of your project.
Then, you should setup that those files are copied to same folder as your exe (bin\debug or bin\release). To to that right click on them, select Properties and notice Copy to output directory setting. It has to have "Always" or "Copy if newer" option selected.
In your code, to open file, use path like this:
string userManualPath = Path.Combine(Application.StartupPath, "usermanual.txt");
that will open file in same directory as application's .exe.
When editing your manual (adding some new text), edit the one in solution, and the changes will reflect to either debug or release or published version.

Replace matching files with local copies VS2015 publish

I remember that in Visual Studio 2010 there was "Replace matching files with local copies" checkbox
Where this checkbox/radiobutton in Visual Studio 2015 ?
In VS2015 it's not possible to set this option in the Publish Window.
But we can do it in another way. Right Click on Project->Properties->Package/Publish Web->Items to deploy
According to MSDN you we have these options
Only files needed to run this application. This is the default value. Visual Studio tries to determine which files are required for
the application to run successfully. For example, this includes
assemblies in the bin folder, files generated during the build, and
files marked as Content. To see if a file is marked as Content, select
the file in Solution Explorer, and check the file's Build Action
property in the Properties window. You can change the Build Action
value to Content to cause the file to be deployed, or change it to
something else, such as None, to prevent the file from being deployed.
Some file types that are automatically set to Content include .master,
.svc, .ashx, .asax, .skin, .browser, .config, .and sitemap. A file
must be included in the project in order to have a Build Action
property.
All files in this project. Visual Studio deploys all files that are included in the project, regardless of their Build Action property
values.
All files in the project folder. Visual Studio deploys all files that are in the project folder and subfolders, regardless of whether
they are included in the project or their Build Action property
values.
UPDATE
I figured out another method how to update all files during publishing. I faced issue when some of my files were not updated properly (config,ascx and etc.), in my inetpub folder I had old version of files. So first I published site in another new folder and then replace files in inetpub folder with files from new folder.

Embedding a PDF as a resource in WPF application

I want to embed a PDF file (which is basically have Product details, Release notes) and wants to open that file from menu bar. What would be the best approach. I need to use this file in installer also. So i'm looking for an approach in which file will be moved to BIN on compilation and from there installer can access that file.
IDEAS ...
Add the file to the project the builds the EXE (use Add existing file in visual studio). Then right click on the file in visual studio, go to properties, and verify that the build action is "Content" and the copy to output directory is "Always" or "If newer" (whichever suits you).
Then this file will always be copied to the same directory where the EXE resides and your application will be able to access it because it's always in the application's directory.
If the installer just takes the BIN directory then it will also be able to access it because the file will reside in the BIN directory.
Have fun!
Finally i did it in following way:
a. We've a folder which contains notes.pdf (used by installshield).
b. Created a pre build command to copy the pdf file from installshield folder to output directory.
c. use process.start("notes.pdf"); to open the file. As it would look in bin directory first for pdf file and we've already copied it there.
It worked for both Installer version and running application from code.

Categories