vsix project context menu visualstudioworkspace - roslyn

I am trying to learn more about creating a VSIX project using the Roslyn VisualStudioWorkspace. I have successfully created a context menu command that appears when right-clicking on a visual studio project. How do I go about getting a reference to the selected project in code without using ENVDTE?

You can import the visual studio workspace using the MEF
[Import(typeof(VisualStudioWorkspace))]
public VisualStudioWorkspace ImportedWorkspace { get; set; }
see this SO answer for more detail

Related

How to create DLL project in VS2017 correctly?

I use Microsoft Visual Studio 2017 Community Edition and I want to create a C++ dll.library. I use the following manual:
https://msdn.microsoft.com/en-us/en-en/library/ms235636.aspx
However there is no manual for VS 2017, only for 2015 and below. VS 2017 haven't project type Win32 Console Application and it doesn't open Win32 Application Wizard dialog box.
How I can create C++ DLL project in VS2017?
Create the DLL project:
In this set of tasks, you create a project for your DLL, add code, and build it. To begin, start the Visual Studio IDE, and sign in if you need to. The instructions for Visual Studio 2017 version 15.3 come first. Instructions for earlier versions come later, so skip ahead if you need to.
To create a DLL project in Visual Studio 2017 version 15.3 or later
On the menu bar, choose File, New, Project to open the New Project
dialog box.
In the left pane of the New Project dialog box, expand Installed and
Visual C++ if required, and then choose Windows Desktop. In the center pane, select Windows Desktop Wizard. Enter MathLibrary in the
Name box to specify a name for the project.
Choose the OK button to dismiss the New Project dialog and start the
Windows Desktop Project wizard.
In the Windows Desktop Project wizard, under Application type,
select Dynamic Link Library (.dll).
Choose the OK button to create the project.
And To use this .dll in a client app follow this link.

Unable to add app.config file in Visual Studio 2017?

Working in Visual Studio 2017; I have added a class library in my project. Now I want to add an app.config file.
When I try to add by "Add new Item" but config file is missing from item list.
How can I do it?
You probably forgot to install workload .NET desktop development.
Go to installation, click to modify and include the workload .NET desktop development.
Check image of installation screen
Just right click your class library. Click on Add -> New Item and you should find Application Configuration file
Note:
If you have a solution without any project or all project are unloaded, you would not find the Application Configuration File
If you are missing visual studio templates,then Close all instance of Visual Studio and Open visual studio command prompt and type,
devenv /installvstemplates
Press Enter. Let the process be complete and now open visual studio. You will get all missing templates under Visual Studio installed templates.
I couldn't add app.config using the GUI tools for my web project. However, I have added the app.config file manually and the build process picked it up and used it.

Where is the project wizard in VS 2017?

I want to create a static library which I want to use in other projects in VS2017 Community but I can't find the right way.
I tried to follow the instructions from here which is for VS2015 but when I want to create a new project I can just provide the name, solution name, location of solution and whether I want to create a directory for the solution or not and with git repository or not.
I remember a project wizard where I could deselect precompiled headers and set the output to a static library.
Did something change or am I missing a component?
Updated answer:
Create new project and under Visual C++ -> Windows Desktop there is a project template called Windows Desktop Wizard which will open the project wizard.
From VS 2017 15.3 Release notes (credits to user VTT from another question)
The Windows Console and Desktop Application templates now create the projects without displaying a wizard. There's a new Windows Desktop Wizard under the same category that displays the same options as before.

Using Visual Studio 2012 IDE, but compile with Visual Studio 2008

Where I work, we are stuck on VS2008 and will be for quite some time as converting the projects/solutions and integrating them back into our build process would take significant time; we're planning on moving to 2013 at some point though. However, I use VS2012 at home and love a lot of the features in the IDE that are missing in 2008.
I've read that you can use 2012 as an IDE and build with the 2008 compiler, but I can't find details on how this is accomplished. Any ideas? If I open one of the masterbuild files in 2012, it inevitably asks to convert them to the 2012 format, which I really don't want to do.
Thoughts? Thanks!
Yes it is possible as can be found on the Visual Studio site. However, I believe it will only give you options of the versions you have currently installed on the machine in question.
Here are the steps as laid out in the link, provided here to ensure the information link does not get broken:
(authored and published by Microsoft)
To change the target Framework
In Visual Studio, in Solution Explorer, open the shortcut menu for your project and then choose Unload project. This unloads the project (.vcxproj) file for your project.
Note: A C++ project cannot be loaded while the project file is being modified in Visual Studio. However, you can use another editor such as Notepad to modify the project file while the project is loaded in Visual Studio. Visual Studio will detect that the project file has changed and prompt you to reload the project.
On the menu bar, select File, Open, File. In the Open File dialog box, navigate to your project folder, and then open the project (.vcxproj) file.
In the project file, locate the entry for the target Framework version. For example, if your project is designed to use the .NET Framework 4.5, locate v4.5 in the element of the element. If the element isn't present, your project doesn't use the .NET Framework and no change is required.
Change the value to the Framework version you want.
Save the changes and close the editor.
In Solution Explorer, open the shortcut menu for your project and then choose Reload Project.
In Solution Explorer, open the shortcut menu for your project and then choose Properties. In the Property Pages dialog box, in the left pane, expand Common Properties and then select Framework and References. Verify that Targeted framework shows the new Framework version.
To change the project toolset
In Visual Studio, in Solution Explorer, open the shortcut menu for your project and then choose Properties.
In the Property Pages dialog box, open the Configuration drop-down list and then select All Configurations.
In the left pane of the dialog box, expand Configuration Properties and then select General.
In the right pane, select Platform Toolset and then select the toolset you want from the drop-down list. For example, if you want to compile with the Visual Studio 2010 toolset, select Visual Studio 2010 (v100).
Choose the OK button.
Try to use CMake. It could manage out of source build. You could create a VS2012 for edit and another VS2008 based for compiling. The source will be common.
From Visual Studio 2012 Compatibility page on MSDN
Some solutions, projects, files, and other assets that you created in
Visual Studio 2010 Service Pack 1 (SP1) will run without modification
in Visual Studio 2012, but others have to be upgraded.
If your original project is 2008 then you won't be able to use it in 2012, sorry.

windows form CLR application in Visual studio 2012 RC?

quick question, im just trying out VS2012 and trying to make a c++.net app but for the life of me i cant find the option anymore when making a new project.
In vs2008 it used to be under new project>visual c++> CLR>windwos form application.
Have they removed the option to make c++/CLR application in .net from vs2012? Or is it something i must download?
Although Microsoft removed the option to create a C++/CLI Windows Forms application, the template files are still installed. The only thing missing seems to be the .vsz files and a registration in the vcNET.vcdir file. I have recreated these files and put them up for download here.
Install the files and you should be able to create WinForm apps in C++/CLI again.
Well, many people have faced this problem. Here is what I follow:
Create a Visual C++ --> CLR --> CLR Empty Project (Obviously you specify the Name and the Directory).
Once it gets created, right-click on the project and select "Add --> New Item".
Under the UI tab, select "Windows Form". Name your form and click OK. This form would get added to the project.
After the form gets added, copy the following code inside the YourFormName.cpp:
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
void Main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Project1::MyForm myForm; //NameOfProject::NameOfForm instanceOfForm;
Application::Run(%myForm);
}
We're almost done...
Now under the Project Properties, expand the Linker section and select "System". Under the subsystem option, choose Windows(/SUBSYSTEM/WINDOWS)
Now add an entry point. Under the "Linker-->Advanced", choose "Main" as the "Entry Point"
Build and Run..Voila!!
P.S.: This is only an empty form ;)
Yes, microsoft has removed the option, here is the response from microsoft (reference):
C++/CLI is a great solution for interop, but we do not recommend
creating brand new UI applications using C++/CLI.
The workaround provided by the link is:
Create an empty C++ solution with both 2012RC and MSVC2010 Express.
Using 2010 Express, create a new WinForm App project inside the folder of the 2012RC empty solution. Close all saving.
Using 2012RC and the "add existing project", add the 2010 Express-WinForm App project into the empty 2012RC solution.
Right click on the project to convert it to 2012RC "format"
It works and it is simple! But I don’t know all the consequences.
Creating the template by yours self:
Create an empty C++ solution with both 2012RC (New Project -> Other Project Types -> Visual Studio Solutions -> Blank Solution) and MSVC2010 Express (New Project -> Visual C++ -> Empty Project).
Using 2010 Express, create a new Windows Form App project (name it “myWForm11” or so) inside the folder of the 2012RC empty solution. Close 2010 Express saving all.
Using 2012RC and the "add existing project", add the 2010 Express-WinForm App project into the empty 2012RC solution.
Right click on the solution to upgrade VC++ projects to 2012RC "format"
FILE -> Export Template ... -> Next> Type in Template name: "Windows Form App, C++ 2012RC" or so and some description too.
Finish
Close solution
Now you can create WF App in 2012RC “as always” (New Project -> Installed -> Templates -> Visual C++ -> Windows Form App, C++ 2012RC).
It works and it is simple! But I don’t know all the consequences.
I just created a new project in VS2010.
Then import it into VS2013.
You will find the form designer doesn't always work with this.
Change the source file slightly and save it.
The form designer will then wok ok until you load in the project again.