How to force Visual Studio to execute .exe instead of .dll? - visual-studio

My solution has 2 projects, both of them are .dlls. These are copied over for my .exe to work. After clicking F5 on my project, I want an .exe to run. Instead, what I get is:
Even if in Project Properties -> Configuration Properties -> Debugging -> Command, my command is correct...
I'm sure it's working for both configurations: release and debug. Projects are building fine, copying to correct directory fine as well. Are there any other properties that I missed?

(1) I agree with Hans Passant's suggestion. Please make sure that you really setup your .exe project as the start up project in your solution explorer window.
(2) Please check that which it really has .exe file in your project output folder. Maybe you set the wrong "Configuration Type" in your start up project.

Related

How to publish my C# project using OpenCV Nuget packages in Visual Studio?

I have developed an opencv application using windows form and C#.
The opencv packages I got from the Nuget packages manager (EMGU.CV and ZedGraph).
Everything works fine in visual studio, but when I publish the project and install the program in my machine, it throws an exception when I click a button that performs some opencv operations.
I guess the opencv packages didn't come along with the final published project, so how do I do to make it export when publishing, I thought it would be an automated process, I have already used other nuget packages and I had no problem with it.
What Am I missing here?
After some days waiting for an answer, and looking for solutions, I've figured it out how to solve this issue.
I came across this question:The type initializer for 'Emgu.CV.CvInvoke' threw an exception
Which led me to this: http://www.emgu.com/wiki/index.php/Download_And_Installation#The_type_initializer_for_.27Emgu.CV.CvInvoke.27_threw_an_exception.
More precisely this part:
First of all, I don't know why the compilation runs fine inside visual studio enviroment and why not when publishing the project as it is. For some reason, the Nuget packges are not enough for publishing the project, you need to add the .dll files manually yourself (not sure why this occurs once I have worked with Nuget packages before and this workaround was not necessary).
To find the .dll files you go to your project directory, then you go to bin\Debug\x64 or bin\Debug\x86 (depends on which operating system you are targetting - 32 bits or 64 bits -in my case I added all .dll files from x86 folder, I guess you can add from both folders if in doubt).
The Debug folder of your project is build every time you run the project inside Visual Studio enviroment, so if your Debug folder is empty then you just need to run the project one time to be able to find the auto generated files inside that folder. Just a side note here, you can use either the Debug or the Release folder inside bin, just remember to check if you compiled the project in Debug mode for Debug folder, or Release mode for Release folder, otherwise the desired folder will be empty, as explained before, I found no differences between the files generated, I added the dll files from Debug\x86.
Once you have located the .dll files, you go to Visual Studio, right click on the project in the Solution Explorer tab, then Add ---> Existing Item.
Go to the folder where the .dll files are, select all and click Add.
Once you have done this, the .dll file will be shown in the Solution Explorer.
Right click on each .dll file added in the Solution Explorer, and open the properties tab by clicking Properties. On the Properties tab, go to option Copy to Directory and change the field to Copy Always (the emgu documentation link provided above states to use the option "Copy if newer", but to make sure I chose "Copy always", it worked fine for me). Repeat the process for all .dll files added.
Now you are ready to go for publishing the project as it is,just remember doing this every time before publishing your project to see if no .dll files are missing, so once you got to final version of your program, run it, and then make sure to check the .dll files, it might have new ones to add or to remove.

Visual Studio not showing all Projects in solution

I'm not sure why, but Visual Studio is not showing all the projects in my solution. I need them to show so I can set as default project under solution explorer. I'm not seeing a fix for this issue in a general internet search. The closest I see is VS not showing files folders, but this is different than my issue. Hopefully there is an easy way to fix it, without adding things again piecemeal. My co-workers can see their complete set of projects in solution explorer so it must be a corruption in my workspace.
Open your ".sln" project file using Notepad.
In this file you can observe listed projects like below
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test.myProject.Data", "test.myProject.Data\test.myProject.csproj", "{6D7F7B84-F3BD-4A19-A069-D144C345B887}"
EndProject
Please add if there any missing projects. If you have old back up or co-workers file, Just copy and paste missing projects to this file.
In my case it works !!
close vs , delete .vs folder then open vs again. it works for me.
I found that re-adding the existing project to the solution worked for me!
I had to copy out changed files in my workspace, fix my permissions/ownership on my directory (it was no owner instead of me), re-do the mapped drive the workspace was on, re-do the shortcut to the Visual Studio project (even though it was supposed to theoretically be the same place I mapped), re-pull the project down, and copy my changes in again. At this point Visual Studio had the missing solutions in it again so I could set startup project and run the debugger. I'm not sure how the ownership/permissions got messed up. I think at one point the other office had a server go down, and maybe my permissions/ownership got mixed up then. I'm not sure why VS wasn't showing the missing projects, but it's fixed after doing the above.
I had the same issue where my colleague saw 1 more project on his computer.
I deleted my .sln file and got the exact same version as he. Problem was still the same.
Solution was: I had an unloaded project. Apparently this is safed in a local user setting file (probably the .suo file). I looked for the unloaded project and loaded it again.
Close the VStudio entire project, go to the main project folder and click on the .sln file to load the entire project agian.
go to solution explorer see which are having (unload), right click and load project with dependencies
sometimes check if the project startup has changed, if changed just right click on the related project and set as project startup
This .sln file structure breakdown offers a great insight on how projects are able to be found and populated into the project hierarchy. My .sln file had lost all its project persistence blocks and thus I had 0 projects under my solution. I copied the blocks from a a previous git commit and this fixed it. I still don't know why the blocks disappeared or the whole .sln file changed
If the other solutions didn't work for you, then try this.
You can add the missing project to the solution file using the dotnet command. To do so, go to the root folder of your project and run the following command from the terminal:
dotnet sln add ProjectLibrary/ProjectLibrary.csproj
The ProjectLibrary/ProjectLibrary.csproj is the path to your missing project.
You can open the .sln file to confirm if the prject has been added. You should see something like:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLibrary", "ProjectLibrary\ProjectLibrary.csproj", "{F042B1DB-F887-44CC-941A-76569A86AF75}"
EndProject
Hope this helps.
I had the same issue. After opening the Visual Studio in Administrator mode it started to work.
Search for VS->Right click-> "Run as administrator"

Visual Studio 2010 F5 Debugging C++ is not Rebuilding

I have a Visual Studio 2010 Ultimate C++ project (not managed or .NET). When I press F5 (i.e., start debugging), I want it to save all the files, rebuild those that changed, link the whole thing, and then run. Instead, it appears to use the last build. Thus, when I try to step into a function or something, I get the following error:
Based on my research, I have verified these options, the first three of which are in the Options dialog (can be reached under "Debug->Options and Settings"):
"Projects and Solutions->Build and Run->Only build startup projects and dependencies on Run" is checked. Some research indicated that it should be unchecked, but in my case I actually do only want it to rebuild the startup project. For what it's worth, I've tried unchecking it, with no effect.
"Projects and Solutions->Build and Run->On Run, when projects are out of date:" is set to "Always build".
"Debugging->Edit and Continue->Enable Edit and Continue" is checked, though it's greyed out.
In the Configuration Manager ("Build->Configuration Manager"), all solution configurations and platforms have their "Build" checkbox checked.
I have also tried deleting all Debug and Release directories as well as the .sdf and ipch directory.
For completeness, I suppose I should mention that I'm using precompiled headers, though I kinda doubt it matters.
[EDIT: I should note that it only seems to be one file (a .h file) that's doing it. I tried renaming it and recompiling, and also removing it from the solution and adding it back in, but it didn't work. ]
I was able to bring my solution back into the right state after deleting all .suo and .csproj.user files. Answer led to this solution. Hope this saves someone time.
I fell into this state after installing Ultimate over Professional and running profiling tools.
Once I had similar problem with my C# project and I think I have tried every possible suggestion available on internet but none worked and then this is what I have done:
Created an empty Project
Added startup function to verify that it does not show any error
Imported all my source code manually one by one
So, Yes, it was the solution. You already have done a lot so I would say you can get lucky by trying here and there however having a new project and importing your individual source file would be faster.
Another solution could be that switching the platform. I noticed that when I when to project properties, the new project I had just created had a platform of 'win32' and my other projects in the same solution had it set at x64. After I switched my project to x64, everything worked just fine. This worked for my interop(C,C+, C#) project and hopefully works for other projects as well.
I have successfully resolved it, try the following:
remove all temporary and intellisense files
remove all project from solution and then add them back(most important)
check projects 'Frameworks and References' to ensure they are valid

Relative versus Absolute path to cv::imread OpenCV

I've got a cross platform error with OpenCV 2.3.1 and 2.4 on both VS2010 and Xcode 4.2
If I use cv::imread while giving the path to the image as an absolute path, it works. It does not work if that is a relative path. I usually put the images in the same dir as the code as well as all other dirs in the project just to be careful.
Much appreciated if anyone can answer this. Thank you!
Harish.
In Visual Studio, when you create a C++ project, it sets the project's working directory to the project dir, not the output dir of the executable.
That means that if you run the project from inside Visual Studio (by using the F5 button or the "Start Debugging" button), the program that you are writing won't be able to see the files that are in the same dir as the .exe file. But when you run the program from Windows Explorer (by double-clicking it) it will work as expected.
To fix this, you need to go in the Project properties window under Configuration properties -> Debugging, and change the Working Directory from $(ProjectDir) to $(OutputPath). You should change this both for the Debug and the Release configuration.
I don't know if this is the same case in XCode, but you can try this solution there too.

Why will my project not debug?

I just downloaded Microsoft Visual C++ and am trying to run a simple hello world. However, when I go to debug, I get the error "Unable to start program 'C:\Users\Sterling\Documents\Visual Studio2010\Projects\test\Debug\test.dll'"
And thats it. It doesn't say WHY it can't start it...it just says it can't. Has anyone experienced this? And know an answer? I'm thinking about just reinstalling it, but was hoping to find an easy solution first. Is there a separate program I need to start .dll files? I just got this laptop about a week ago so I may not have it yet. This is on Windows 7. Thank you for any help.
You have built your project as a DLL. You cannot run DLLs standalone. If you meant to build it as a program (.EXE), change the Project Settings.
Right click Project in Solution Explorer, click Properties - edit Configuration Properties -> General -> Configuration Type to be "Application (.exe)".
If you want to build (and run) your project as a DLL, you will have to also write a program that uses it in order to to test it. You could do this as a separate 'TestDll' EXe project in the same solution as your existing DLL.

Resources