Where does visual studio setup project get the primary output file? - c#

I am trying to create a setup project for my C#-application in VS 2010. I am using an post built event during the creation of the c#-application. This event appends data to the binary of the application, because i need this data later.
The Problem is, that the file in the output-folder contains this appended data but the installed file of the setupproject doesnt contains it. My Question now is, where does VS get the output file for the setup project, so I can append the data to this file?

Try adding "File" instead of "Project output" to your setup project.
Or you can just modify your output in /obj/release (or obj/debug) folder instead modifying it in output folder. (if you look on primary output properties - you will see that it uses files from obj... folder and not from output folder)

Related

Generating a file during "Build", c#, Visual Studio

How can I generate a file during "Build" in Visual Studio using C#?
I want to create a .txt File and add some text in it. The file should be created directly when I press Build and save it in a place where the Release or Debug Folder is.
You should have a look at build events.
Typically you can run any kind of script pre and post build - including the (re)generation of a text file.
To copy files into the output path, you can use the OutputPath variable. See the MACRO section and this list on how to use them.
As by #Oliver's comment: if it is a static file, you can just include it in the project using its properties and select: Copy if newer.
Taken from the documentation:
And a subset of the MACROs

how to set image in Visual Studio C# Windows Forms with Image.FromFile

So I'm trying to set a custom image for a form application I've made. The images I'm trying to target are in a folder called "Images" on the same level as my Solution file. The solution file is a C# windows forms (net core framework) solution. It's a basic form app that I want to display an image based on a users selection, however right now I get an unhandled exception everytime I try to set the image with this code:
picFood.Image = Image.FromFile("../../Images/burger.jpg");
The exact error is "System.IO.FileNotFoundException: ../../Images/burger.jpg"
In another totally unrelated solution this works. Folder structure is the same. A folder called Images, on the same directory level as the .sln file holds the images there. They're in my solution explorer and everything. I've tried this with one "../" and no "../" as well so I'm not sure what to do from here.
Files with relative paths are opened relative to the working directory of your application.
In this case, when launching from within Visual Studio, the default is the bin folder where the compiled application is put by default.
So if your binary is in <project dir>/bin/Debug/App.exe this path will resolve to <project dir>/Image/burger.jpg.
If you have changed something in your build configuration, or your application switches directory at runtime (e.g. via Directory.SetCurrentDirectory), this path may be different than you expect.
To understand your issue, I suggest you start looking at what your working directory is. You can obtain that in your code via Directory.GetCurrentDirectory().
You can also resolve your relative path using Path.GetFullPath.
Print these two values to see where your program attempts to load the file from.
Keep in mind that any image files you put in the solution/project folder will need to be copied with your binary if you want to use them.
To use relative paths without .. you can copy them alongside your binary during compilation, see:
VS2010 How to include files in project, to copy them to build output directory automatically during build or publish and Copying Visual Studio project file(s) to output directory during build for how to do that.

What is the easiest way to make a backup in visual studio 2013?

I want to make a backup from the whole project. I also need to rename every backup. I'dont like the way to copy the project folder and rename the folder and the project file.
I've already tried to make it like that:
http://jasonfaulkner.com/VisualStudioExpressProjectBuildBackups.aspx
But it doesn't work, I am always getting the error "Invalid parameters"
Does anyone already tried this?
Thanks
The DPack extension for Visual Studio includes the Solution Backup tool that creates a zip archive of the solution and auto names it.
Manually edit .sln file
This method is entirely aimed at renaming the directory for the project, as viewed in Windows Explorer.
This method does not suffer from the problems in the Remove/add project file method below (references disappearing), but it can result in problems if your project is under source control (see notes below). This is why step 2 (backup) is so important.
1- Close Visual Studio.
2- Create a backup of your .sln file (you can always roll back).
3- Imagine you want to rename directory "Project1" to "Project2".
If not using source control, rename the folder from "Project1" to "Project2" using Windows Explorer.
4- If using source control, rename the folder from "Project1" to "Project2" using the functions supplied by source control. This preserves the history of the file. For example, with TortoiseSVN, right click on the file, select TortoiseSVN .. Rename.
5- In the .sln file, edit all instances of "Project1" to be "Project2", using a text editor like NotePad.
6- Restart Visual Studio, and everything will work as before, but with the project in a different directory.
Alse would recommend TFS, a powerfull tool to do what you pretend. You will be able even to recover previous versions of specific files,if you have any error and you have troubles find it you can see what changes you did since last "check in " etc. There are many options

PreBuildEvent not reflecting in project dependencies

I have two C# projects, one of them, the library, contains a database file which is modified during PreBuildEvent. Its contents are correctly updated and available in bin\Debug folder of this library project.
The problem occurs because in the other project, the UI application, the database file is the same as before my changes in PreBuildEvent.
In the example below, I will use a text file (it behaves the same):
ProjectLib.csproj
TextFile1.txt
Build action: Content
Copy to Output Directory: Copy if newer
PreBuildEvent:
echo test > $(TargetDir)TextFile1.txt
Contents of TextFile1.txt in ProjectLib\bin\Debug:
test
Application.csproj
Contents of TextFile1.txt in Application\bin\Debug:
"empty"
From where the database file is picked? From $(ProjectDir) or $(TargetDir)? EDIT: The database file is picked from $(ProjectDir). You can see this executing the build using msbuild. At the end there is a target named _CopyOutOfDataSourceItemsToOutputDirectory and this shows the source as $(ProjectDir).
Is there a way to modify the file in the PreBuildEvent - the file in library bin\Debug - and have it correctly output to application bin\Debug?
Why are you designing your build system to have two separate projects overwrite a critical dependency?

Class file with .bak extension in Visual Studio 2012

Is a class file like MyClass.cs.bak used at run-time even though there is a class file by the name of MyClass.cs within the same Visual Studio project?
Both files are included in the project. The project is of Web Application type, so everything compiles into a single dll when deploying. I am not sure if during compilation, the .bak file is ignored.
I am working on a project in Visual Studio, in which some past developer has included both these files within the project.
If you click on the file in Solution Explorer and look at the Properties window, you'll see a property called "Build Action". This defines whether the file will be treated like code ("Compile"), included as a resource ("Embedded Resource"), or ignored ("None").
When a file is added to a project, the default Build Action is selected based on the file extension. For .bak files, which have no particular meaning to C# projects, the default "None" should be selected, and the file will be ignored when compiling the project.
No.
The .bak file is treated as a normal text file.
This is quite easy to test. Create a new class file, with a class name foo.
Now create a new .cs.bak file and type in the same code.
when you compile the project, you would expect a duplicate class declaration error - this does not occur.
As far as I know (and check), by default, a *.bak file is not considered as a C# class file in a VS Project. It's just another text file which doesn't complied into the assembly as a class module - Therefore, by the way, why you don't get duplicate class names declaration exception.
You can always tell to VS to treat it as a compilable c# file: Properties -> Build Action -> Compile.
It's just look like a backup (bak) source file - just for history purposes, I assume.

Categories

Resources