Visual Studio 2015 Project Templates (C++) won't create project file in specific location - c++

I'm trying to find how to create my own VC++ project template with all parameters set up for future development. But suddenly I appeared to stuck at a little problem: VS2015 won't create given structure inside of the project folder.
That's how my directory looks like inside of .zip file used for templating inside of Visual Studio:
Project/%ProjectName%.vcxproj
Project/%ProjectName%.vcxproj.filters
Project/%ProjectName%.vcxproj.user
Src/Main.cpp
MyTemplate.vstemplate
To be precise, it won't place .vcxproj file into the
%created_project_folder%/Project
directory, but directly into
%created_project_folder%/
directory instead, ruining file dependencies specified inside of project file. E.g. "include ../Src/Main.cpp" won't work because it will seek for file in wrong location.
I attached link to my .zip file below.
https://fex.net/#!654242360762
You can try to copy that onto #user#\Documents\Visual Studio XXXX\Templates\ProjectTemplates folder and then create project in VS. Project file will be created on the root instead of custom location.

Related

Why do the c++ files in my folder not show when I try to open them in Visual Studios?

I am trying to open up a pre-existing folder in visual studios that has several c++ files. When I look at them on my desktop it shows the files as there, but when I go to open them in visual studios they no longer show up in the folder. I am using a virtual PC and this folder is one I opened from a zip file if those factors make a difference.
Folder outside of VS:
vs. Folder inside VS:
Normally adding a project requires a folder to contain the .sln file. If you don't have a .sln file, you have to create a C++ project. We could open the project by selecting the .sln file to be added in Open>Project/Solution, just like the picture I uploaded.

Creating visual studio template projects

I created a project template as described here: vs create template When I created a new project using the template, source files haven't added to project. I am using visual studio 2017 community edition. Actually source files (.h and .cpp) are visible in the solution explorer but they are not included in the project folder. So when I try to open them, ide gives me this message: "The document cannot be opened. It has been renamed, deleted or moved."
Is this a bug ? How can I fix it ?
It seems this is a bug. I solved it like this:
Visual studio automatically generates a .zip file containing the template project settings. However in that .zip folder, it doesn't include source files. I manually added every source files to the zip. Then I added fallowing lines to the automatically generated "MyTemplate.vstemplate" file.
<TemplateContent>
<Project File="yourProjectName">
<ProjectItem>source.cpp</ProjectItem>
.
.
.
</Project>
</TemplateContent>
and it worked.

Visual Studio looking for a file in the Desktop directory instead of the Project Directory [duplicate]

I've got an a project (native C++ compiled to .exe) that runs fine outside of VS 2010, but inside of VS (with or without the debugger) it gets stuck trying to find a text file located in the same bin folder as it.
Any ideas as to why this would happen? My hunch is that VS messes with where the code looks when trying to open a file, but I don't know enough details to correct this.
Some details:
My .exe calls a function from a .dll I wrote earlier, which in turn tries to find a text file specifying that function's parameters. For convenience I've placed all of these files in the same folder, so finding the text file wouldn't be a problem.
Before opening the file, the function checks that it exists using:
PersistentAssert(Utility::FileExists(Filename), "Parameter file not found");
In VS 2010 this line causes "Parameter file not found" to display, but outside of VS the program manages to find the file.
When launching an executable from visual studio by default it uses the project file directory as the current working directory. You can change it in Configuration Properties -> Debugging -> Working Directory.
However I don't think it's correct behavior to search your programs datafiles etc from the current working directory. Instead your program should find out the directory of the executable and find the files in that directory.
Processes have the concept of a "current directory", which may or may not be the same directory as where the .exe file is located. It sounds like when you run your program inside VS, the current directory is something other than where your .exe is.
Somewhere in the project settings, there should be a place where you can choose what directory will be the current directory when your program starts inside the debugger. Set that to the same location as your .exe and you should be good.

How to create a folder in Visual Studio C++ 2012

I have started my first bigger project with Visual Studio 2012 in C++. I will structure my Source-files in folders, but I can not find where I can create real folders, like in the windows explorer. So here is my question.
How can I create real folders in my project?
The IDE has a command for that, "New Folder". It is even present in the Project + Add context menu, something you can see when you look at the context menu with Tools + Customize. It is however hidden in the C++ IDE. Intentionally.
Its important to understand why it is hidden. It keeps you out of trouble, the kind of trouble you'll get into when you create folders with Explorer.
At issue is the way C++ files get built. They produce an .obj file when the compiler is done with them. That obj file is stored in a directory whose name is a project setting. You see it with Project + Properties, General, Intermediate Directory setting. For an individual .cpp file, it is C/C++, Output Files, Object File Name. The default for that one is $(IntDir) a macro that tells the compiler to use the Intermediate Directory setting. With the default settings, all .obj files for the Debug build end up in the Debug subdirectory. Release subdirectory for the Release build. Regardless where the .cpp was stored.
Maybe you see the bear trap by now. If you create a subdirectory with .cpp files then you'll get in trouble when that subdirectory has a .cpp file whose name is identical to another .cpp file in another subdirectory. They produce an .obj file with the same name. One overwrites the other, which ever one was compiled last. That produces very mystifying linker errors. You'll get duplicate symbol errors because the last built .obj file is linked twice and missing symbol errors for the overwritten .obj file.
So go ahead and create a subdirectory but beware this problem. You have to change the Object File Name setting for the .cpp file if such a collision happens.
This is mildly annoying, however, here is what can be done:
Create the new folder in Visual Studio. This does not create a new folder in the file system. Add a new item to the folder. Choose the proper directory for the item.
For example, if your project is at %Documents%\Project, and your new folder name is Folder, then you add a new item to that folder at %Documents%\Project\Folder.
Visual Studio 2012 will put the item in the folder where you want it. If you add a new item, it will default to the same folder. That is where the annoying part comes in. If you create 3 folders for all your project items and try to add a new item to each folder, Visual Studio will try to put all 3 items in the same place in the file system (the last folder you added a new item to), while putting items into the correct Visual Studio folder.
It is possible there is a setting for this in Visual Studio. I haven't found it. I also haven't looked that hard.

Unable to include header file in C++ console application project

I have been trying linking of a .lib file and also including a header file in my C++ console application project. I copied the C++ header file from one of my other projects, and pasted it under Header Files folder in console application project. Here's the screenshot to see: http://i.imgur.com/JFFIn.png
However, when I try to include the header in my code as #include..., I do not get an intellisense with my header file's name. (I only see targetver.h, stdafx.h and Debug folder)
I tried to point Add additional include directories in my C++ console application project properties to the Project folder itself, but that doesn't seem to help and the file still doesn't show up.
If I write the name of the header file as #include "DllTest.h", I get an error saying: Cannot open include file: 'DLLTest.h': No such file or directory c:\users\ht\documents\visual studio 2010\projects\dlltest\dlltestconsole\dlltestconsole.cpp
How is the header file included in here, so that it starts appearing? If I add a new item > Header File, name it to DLLTest.h and copy paste the header files content here, it just shows up normally. How will the header file which is copied - pasted into Header Files folder show up in the code?
In C++ projects, the things that look like folders in the Solution Explorer aren't actually folders, they are filters. They are UI-only entities that can be used to organize project items in the IDE. They do not in any way reflect the structure or location of items on disk, though. You can add a file from any location on disk to any filter in the solution.
The compiler knows nothing of these filters; it only knows about files as they exist on disk.
In your case, the files are not located in your project folder. You'll either need to:
copy your files into your project folder, then add them to the project from there (right-click on the solution then Add Existing Item), or
add the files from where they are, then add their location to the "Additional Include Directories" property in the project properties.
I do not know of any way to have the IDE automatically move files to the project directory when you copy and paste them into the project. The C++ project system is fundamentally different from the project system used for C# and VB.