Can I create a Visual Studio 2019 project from existing C code? - visual-studio

Here is my current setup:
Some C code (some embedded code) in a folder and subfolders. Organised as I needed and how the embedded editor needed.
If I use Eclipse to create a new C project and place the project file in the root of my sourcecode, then Eclipse will find all folders and files, then index them correctly. I then able to browse the files as a project, functions linked to other files, defines are showing up correctly.
Now, our version control is Visual Studio 2019, and I'm looking for a solution or guide, how to open the same file structure in visual Studio instead of Eclipse. I don't want to open the Eclipse project, I try to drop the use of Eclipse, so I can just use one tool to version control the files and browse the code for editing. I also don't want to compile, debug in visual Studio, I can use the dedicated environment for that. I only want to edit the files like it would be in Eclipse, save the files as the VS editor is much better than the embedded editor. (By the way, the embedded studio IAR and it's editor is horrible, hence why I used Eclipse in the past, but I don't want to open IAR project in VS, just a nice editor needed from VS.)
Any suggestions? Anyone done this successfully?

When you open VS2019 directly (i.e. not via a source or project file) you should be presented with a start page that includes this:
Select "Open a local folder" and it will present the project from the root you select. It will even apply IntelliSense for code completion for symbols within the selected code base. For headers external to the project tree, you can add include search paths to get better navigation, browsing and completion.
A more comprehensive integration with IAR is possible using VisualGDB extension as described here.

Related

Visual Studio 2013: How to copy a project's properties to use in another project?

I tried to copy a project's properties to use in another project as instructed in the stackoverflow question Visual Studio: can I copy a project's properties to use in another project? but it does not work. When I open the created PropertySheet it seems that nothing is copied to it from the original property settings. The above link seems to be for VS 2008 but now I am using 2013. What might be the fault.
Caveat: Tested only on a relatively basic C++ project. But it worked!
Right click on your source project (in the solution explorer)
Unload project
Right click on your destination project and unload that as well.
Right click on each project and Edit {project}.vcxproj. The projects' configuration files can now be edited. (Yes you could also just find the file and edit it directly)
Copy/replace elements from the source to the destination.
Reload both projects. They should reload withut problems.
Tips:
If the reload did not work then copy/replace in pieces instead of the entire project to isolate the problem.
Don't replace the "ItemGroup" and the "Globals" PropertyGroup because these (XML) elements identify the projects in the context of the solution. But you should be able to copy/paste everything below these elements from the source .vcxproj file to the destination one without problems.
Try this on two "empty" projects before proceeding to your magnum opus. And definitely make a backup of your projects before trying this. (you are reading all of this before starting, right? Of course you are...)
This solution works better than others I have seen because it sets and unsets settings completely. It's a total replacement, not just an additive one.

Visual Studio 2013 - Add New Scripts in /Scripts/ Folder in .csproj

I've begun to really enjoy a quick contextual menu that appears when adding new Typescript files into my Visual Studio Web Project. You can see from this image that I can quickly select that I want to create a typescript file without much fuss. Right clicking all I have to do is go through a folder in Scripts > Add > Typescript File to make said file.
I've begun adding my scripts to another referenced .csproj class library, and unfortunately for me, the context menu doesn't work in the same way. Shown here:
I'm wondering if there is a way to reclaim this menu context without having to convert this project into anything different? Or, if changing the project will have minimal impact on everything else.

Create Visual Studio Solution from Batch File

Visual Studio seems to consist of a single solution file (*.sln) along with one or more project files (a C# project would have the *.csproj extension).
I have been playing around with a console application that parses existing directory entries to create solution files with the associated project files.
It works, but every time I run into a new project here at work I find myself spending a week or more debugging my console project so that it can churn out a solution for that particular work project.
Is there something out there already that can create a VS solution out of an existing file structure?
As you can tell from my screen capture below, these projects are nested very deep, so it would take a very long time to do this with the apps folder below with the "by mouse" technique in the Visual Studio IDE.
I created the custom console application that is posted in this post:
https://stackoverflow.com/a/22153536/153923
I invite others to contribute how they approached this solution, though.
So, I found out today that this feature already exists in Visual Studio.
Link 1: How to: Create a Project from Existing Code Files
Link 2: How to: Create a Project from Existing Code Files
Basically, though, it says this (just in case the MSDN links get changed or deleted):
You can create a Visual Studio project from an existing app—for example, an app that you obtained from an online source. Project and solution files are created on your computer and the other relevant files are added. A project can be created from Visual C++, Visual Basic, or Visual C# code files.
Security note Security Note
We recommend that you determine the trustworthiness of existing code files before you import them into Visual Studio, because Visual Studio will execute some of the code in a fully trusted process when you open the newly created project.
To create a project from existing code files
On the menu bar, choose File, New, Project From Existing Code.
The Create New Project from Existing Code Files wizard opens.
Use the wizard to specify the details of the existing code files that will be added to the project and the application that will be created when you build the project.
Another good answer was given by cbp in Visual Studio: Create a web application from existing code:
--
OK I figured it out. It's weird, but the following steps will work:
Open fresh copy of Visual Studio
File->New Project, select Web Application
Use the following settings:
Name: Website (this is the name of the existing folder with the website files in it)
Location: C:\Temp\ (anywhere will do for now)
Solution Name: TheProject (name of the existing project's root folder)
Check "Create directory for solution"
Delete the auto-created Default, Global and Web.config files
Save All and close Visual Studio
In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.
Double click on the sln file to open Visual Studio again.
Select "Show all files" (at the top of Solution Explorer)
Right click on any files or folders you want to add and select Include in Project.
Great idea!

Deploy a VSPackage to create a new project type using Setup Project

I create a new custom project type using a VSPackage project inheriting of MPF library (http://mpfproj11.codeplex.com/). As a result I obtain a .vsix but I need add this project type using a .msi. I'm using the Visual Studio 2010 Setup projet for it. In my setup project I add the content of the VS Package in the same directory where the .vsix put then, but I think Ineed to put in the registre the new type of project because when I use the setup , the project template does not come out in Visual Studio and when I give double click the file with extension of the type of new project and does not recognize it. When I look the registry after install the vsix, this was one of the things that I found diferent. I add this entries in my setup project but It's not working yet.I'm missing something else?
In the projecttemplatedir is the directory where I put the .dll of the project type, the vsixmifest and pkgdef. The project template is in [User]\Documents\Visual Studio 2013\Templates\ProjectTemplates\[Name of new Project Type]\[projecttemplate.zip]
Best Regards
PS: The project type is for VS 2013 but I'm using the VS 2010 Setup project ;)
OK, so first the "don't"s of doing this:
In general, if you are installing via MSI you shouldn't be doing anything user-specific -- no writing in HKEY_CURRENT_USER, nor writing within their Documents folder, LocalAppData, or Visual Studio folders, etc. If you see yourself writing files or registry keys in either of those places, that should be your hint that there's a better way to do what you're trying to do. For what you've shown so far, this raises more than a few red flags for me.
Second, don't ever go writing keys into 12.0_Config. That part of the hive is nothing more than a cache that's built up from other parts of the registry and on-disk .pkgdef files from extensions. It's rebuilt in any number of senarios, including installing new extensions. Any writes there you should presume will get blown away at any time. If you need to write things there you should either (a) write in HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\[version] and run devenv /setup or (2) [preferred] put your keys in a .pkgdef inside your extension which gets merged into 12.0_Config for you automatically.
Now the dos:
You said you already had a .vsix produced by the SDK: you can put project templates in there. You can then register those templates in the .vsixmanifest and those will pull in. That's far easier than mucking around with files in Documents -- that's the user's directory...don't go playing with that.
Once you have a .vsix that does most of what you need, you should simply take the files within that and install the files in a folder within C:\Program Files [(x86)]\Microsoft Visual Studio 12.0\Common7\IDE\Extensions. Even better, you might just want to WiX toolset to build your installer, since it has built-in support for installing extensions. It also has built-in support for invoking the "/setup" process if that's what you need to do as well. Visual Studio Setup projects are no longer supported in newer versions of Visual Studio, so you're better off starting with a technology that isn't already obsolete. WiX is even what we use at Microsoft to do the setup work for Visual Studio itself, so it's definitely up to the task.
Last point: almost everything when it comes to Visual Studio extensibility can be done with a VSIX directly, so presume there's a good way to do something that way before falling back to an MSI. Internally, we can register the entire C# and VB language services with just a VSIX -- they're quite powerful.
I found the answer in this link Registering Project and Item Templates. I set projecttemplatedir entry with
[User]\Documents\Visual Studio 2013\Templates\ProjectTemplates[Name of new Project Type][projecttemplate.zip] that is where i put the project template.

Create a physical copy of a source file in Visual Studio

In Visual Studio, if I try to copy a file from one project to another (by using Copy and Paste or by dragging the file to the new project while holding the Ctrl key) it creates a reference to the source file in the original location. Is there a way to create a physical copy of the source file and place that in the target project source direction without having to resort to using Windows Explorer to copy the file manually?
It's not pretty, but when I want to do what you're suggesting, I double-click on the file in Visual Studio, which opens it. Then I do a File->Save As, choose the right directory and save it. All from within Visual Studio. This is usually followed by adding the new file to the other project.
Was just doing this and realized I should mention a side-effect. Depending on your source control (in my case, TFS 2010), doing this from within Visual Studio may modify the location of the file in the project. For me, this means making sure that neither the file nor its project have any pending changes, doing the save as, then doing an undo of the change this causes in TFS 2010 (project change, file add and delete).
From http://msdn.microsoft.com/en-us/library/0fb6xxhb.aspx:
If you are working with solution items, Visual C++ projects, or other similar projects, you are always working with links in Solution Explorer. If you are working with Visual Basic projects, Visual C# projects, and other projects, you might be working with links or files.
Essentially, the answer to my question is 'No'. In most cases, I must use Windows Explorer.

Resources