Copy "Filesystem on Target Machine" to bin/Debug and bin/Release - c#

I did a lot of googling, but didn't find any answer for this problem so far...
I defined the File System on the Target Machine for my program in Visual Studio 2010.
It includes all of the external Files (like XML's and batch files) which are needed to run the program. The files are stored in the Program Files folder.
The thing is now that if I try to debug my program, it says that it can't find the needed files in MyTool/MyStartProject/bin/Debug.
Is there any way to tell visual studio that it must copy these files to the Debug and Release folder to run the program?
I don't want to copy all files to the bin folder every time I want to run my program.
Thanks for any hint!
EDIT:
This is how my 'File System on Target Machine' looks like:
I created it using the built-in editor and Drag&Drop of the files and folders I need.

Add the needed files to your project, and for each file, open File Properties pane, select "Copy always" in the Copy to Output directory property.

Related

How to do exe file no root directory?

By default, build path \debug\x86\ with:
db (folder)
log (folder)
*.exe
*.pdb
*.config
I want to move *.exe (pdb and config) to my folder bin (\debug\x86\bin)
I do the next post build script
ROBOCOPY "$(TargetDir) " "$(TargetDir)bin\ " *.exe *.config *.pdb /IS /MOVE
But when I run the application is crash (or start by Visual Studio)
The project contains other folders. So I want to put the files in different folders.
I want this structure
db (folder)
log (folder)
bin (folder)
About why VS threw that error message and you can't start the program
in VS:
For C# projects in VS, it has default Output path, like what Larry suggested above, when we try to simply start or start with debugging the program, VS will call the output xx.exe according to TargetDir. Since you use a post-build-event to move the output xx.exe from $(TargetDir) to $(TargetDir)bin, every time when VS try to start the program, it won't find program since it's actually not in $(TargetDir) path.
Note: The $(OutputPath) and $(TargetDir) refer to the same path when building by msbuild.
I want to move *.exe (pdb and config) to my folder bin
(\debug\x86\bin)
It's not recommended behavior for C# projects in VS. I assume you may have log and db folders in your current project, if the files in them are set as Content build action and CopyAlways or CopyIfNever, then no matter what output path you set, the output structure is like this:
There's no need to create a new bin folder at current path and move the *.exe, *.pdb, *.config into it. It will affect the normal debug behavior in VS, also it may cause unknown error if the xx.exe depend on the database in db folder. (After changing path, the xx.exe may try to search it in wrong path)
Not sure what VS version you use, you can check this issue. Msbuild is the build engine in VS, and vs use it to build C# projects. You can find its path in your machine and check its typical structure:
--Msbuild.exe
|
--necessary files
|
--referenced assemblies
|
--other folders
In summary, using the post-build script will call the crash cause VS won't find the xx.exe. And there is no valid way to get the structure you want, cause the original structure is expected behavior of VS for C# projects. So maybe we can just let it in normal situation it should be.
Update:
If now I want to publish the program. Of course now I build the program in release mode. The output structure is:
RootDir(name:xxx) ---xx.exe
---xx.config
---log folder
---log file
---text folder
---txt file
---db folder
---db file
For your requirement, why not just create a new bin folder and put the xx.exe, xx.config into it. Then rename the Root folder's name, change it manually to this:
ProgramName ---bin folder
---xx.exe
---xx.config
---other referenced assemblies
---log folder
---log file
---text folder
---txt file
---db folder
---db file
All you need to note is make sure you program can find the required files like this. Since you may depend on those files by code, a simple sample is using path in this format: #"..\text\test.txt", the .. means the above directory. So if you use statement like #"..\db\database file", your program can find the necessary files.
But note this way will affect the noraml debug behavior, so please leave all in normal structure when you're debugging. And use the special structure when you try to release it.
Instead of using ROBOCOPY, change the actual build location of your project.
Go to Project -> Properties -> Build and change the output path to /Debug/x86/bin.
This should then debug properly.
VS Docs on Output Path

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.

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

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.

How to copy a file to application folder in set up project during insatllation. File is in set up folder

I have a xml file in the setup folder of a windows application. Now during the installation how do i copy this file to my application's folder so that it can be copied to this path C:\Program Files (x86).......
I can not add the file to the application folder in the setup project because the content of file might change after build of setup project.
Its an external xml file in located inside set up folder. and I want to copy this file on installation path(C:/Program Files...) during installation. I will give this file with msi installer in side installer folder.
Please provide any idea if someone have....
If I'm understanding you correctly, this might solve your problem, or at least get you started:
Include the file in the main project (for instance in a folder called "resources"). Right click the file in VS, choose properties, and set Copy to output directory to Coppy Always.

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