How to do exe file no root directory? - c#

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

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:

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

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.

Visual Studio 2010 Manage Output Files

I'm new about code developing with Visual Studio 2010 and I would like to ask you a simple question about something after build a project.
I have a C# project and when I build It in Release mode some file are created and some of them copied from another in to \output\bin\Release\ folder. My question is that How can I manage that which created dll or created file will be in \output\bin\Release\ folder.
I tried to take a look at build properties of project but I could not find any option about it.
Thank you.
Actually I do not need this dll in my project output folder because I
add this dlls as a reference to my project
And this is exactly why this file appear in output folder.
There are several ways to "put" file in output folder. For normal files in the project you can set property Copy to Output Directory.
If we talking about dll's, (as mentioned Hans), there is Copy Local property for each assembly in References.
By default VS set this according to our GAC, so if you are using 3rd part assembly or from another project VS will set this property to True and file will be copied to output folder.
If you don't want to put this file in output folder, just set this property to False. But remember, at run time this assembly should exist.
For more information: How to: Set the Copy Local Property of a Reference
Another explanation: you just messed up with Output path in the project properties and two project has the same output folder. :)
I suggest that you ignore the extra files that are created. One way to do this is to configure the destination of these to a different location.
I use this:
property pages->General
- Output Directory = $(SolutionDir)..\link\
- Intermediate Directory = c:\temp\vc10\$(SolutionName)\$(Configuration)\
Use the same settings for debug and release.

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.

Wrongly created output folders with Visual Studio 2008

I have a solution with many projects. There is actually a Core project and a few plugins. I changed OutputPath for all plugins so all binaries end up in the Core bin\debug folder. (this is necessary as the Core do not have a reference on plugins, hence it does not "include" plugins binaries when it is compiled.)
So basically my folder structure is as follow:
Solution
MySolution.sln
Plugin1\
Plugin2\
Core\bin\debug
Each plugin OutputPath is "..\Core\bin\debug". When I open the solution Visual Studio creates a folder "Core\bin\debug" in Solution's folder parent as if the relative path starts from .sln file. However when I build the solution the binaries are output to the correct path ("Solution\Core\bin\debug").
Core\bin\debug
It looks like a Visual Studio bug to me, but maybe I overlooked some option somewhere. Any ideas how to resolve this problem ?
PS: I know this not a critical issue as everything build and works fine, however I dislike the idea of meaningless folder hanging around
Rather than changing the output location of the plug-ins, what you could do is create a post-build script (Properties \ Build Events tab) for them that will copy the them to the Core folder. That would prevent the confusion with output folders.
This command line should do the trick for you:
copy "$(TargetPath)" "$(SolutionDir)Core\$(OutDir)"
If you need to copy .pdb and .config files as well, you can add more lines:
copy "$(TargetPath).pdb" "$(SolutionDir)Core\$(OutDir)"
copy "$(TargetPath).config" "$(SolutionDir)Core\$(OutDir)"
If you really want to do it with a single line, this should also work, though it's not as clean:
copy "$(TargetPath)*" "$(SolutionDir)Core\$(OutDir)"
If you're not using the same output path in both the main project and the add-ons, you'll need to replace $(OutDir) with a hard-coded value. If you have them set to target the typical "\bin\Debug" folder (or have just left the defaults in place), then you can get away with using the $(OutDir) value.
Instead of using "..\Core\bin\debug", use "$(SolutionDir)\Core\bin\debug".

Categories