VS2010 extensibility: how to do custom actions on pressing F5 - c#

I need to achieve some kind of extensibility for a custom project template.
Having a C# code file opened, if...:
...current project has some specific type id.
...code file is a class and inherits some concrete base class.
...user pressed F5.
...I'd like to...:
...start an arbitrary program (a console application).
...attach Visual Studio to the process of the arbitrary program.
...debug.
Actually I'm absolutely lost and I don't know how to do so. I know I need Visual Studio 2010 SDK, but I don't know how to create an extension doing what I need to achieve.
Thank you in advance.
UPDATE
I'm doing some research in Stackoverflow Q&A and I'll be adding questions related to my own one:
Visual Studio 2010 Extensibility - Override Build Action without effecting cproj file
"Attach to Process" as a post-build event (This seems fine, but I don't like the approach. I prefer a full Visual Studio integration. Anyway, it gives a hint).

I guess the best way to try is VS addin that will catch the Run (F5) command and handle it as you wish. See this article as a starting point for catching command from VS addin: How to: Add and Handle Commands. And these for attaching to process from VS addin Attach to process for lazies and Visual Studio Add-In To Automatically Attach to Development Server
Hope that helps to find a solution for your needs.

Do you consider the use of third-party extensions, for example, the free DXCore Visual Studio Extensibility Framework? It can do what you need.

First of all, thank you everyone for the info, it has been useful.
Basically I got the way to do what I'm looking to achieve.
Because I want to assist others in a similar situation, I'd like to share what I'm using to solve everything:
NRefactory as C# code parser. It works like a charm! You can get a lot of info from a code file.
VSPackage Visual Studio 2010 SDK project template.
In order to attach to a process I'm going to look forward for Dmitry Pavlov's suggestions.
Interesting links:
VSPackage how-to: http://msdn.microsoft.com/en-us/library/bb164715.aspx
As soon as I got everything working, I'm going to edit this answer and give more detailed info.

Related

Alternative to ClickOnce

So I have been looking around for a way to have a window form application (c#) check for an update each time it's launched and even send a message to an active user that an update is required. This entire program will be ran in a S:\ (shared) folder. I know some one else recommend click once but everything I can find in it is from Visual Studio 2005 and well that's out dated. Anybody know a different one?
Try https://github.com/squirrel/squirrel.windows
And intro to this on dotnetconf 2015: https://channel9.msdn.com/Events/dotnetConf/2015/Squirrel-for-Windows-installing-NET-apps-the-way-it-should-be
You could give this a try https://simpldeploy.com
It's a bit different to squirrel, it's integrated into VS and does not require scripting altough it can be automated with the simplDeploy.packager.exe found in the extensions install dir.

Visual Studio 2013 C# Interactive Window

Is there C# interactive window for VS 2013, or any other similar way, without installing VS 2012.
I tried C# Repel, C# Snippet Compiler and Mono Command Prompt, but, all of them don't provide the features of C# interactive window packed with Roslyn for VS 2012.
UPDATE: Found a total better alternative!!! Try CShell, it is free and open source! "A simple, yet powerful, C# scripting IDE" as they promote it.
Check my tweet which was also favorited by Scott Hanselman :)
My old recommendation was: LINQPad
Best way is to install VS 2012 and use C# interactive window provided with its Roslyn. While doing that, wait Microsoft to release C# interactive to VS 2013.
This is taken from one of the links above:
http://social.msdn.microsoft.com/forums/vstudio/en-US/0da45fe7-fbe2-4074-b52f-dc8d7c4b2ba3/c-interactive-in-vs-2013
It worked for me, so hopefully this will help the next person :)
Hi SpencerGR,
I just got upgraded to VS 2013 and wanted C# Interactive, and this is
the first hit when I searched for it, so I figured I would place my
answer here...
Didn't make sense to me that the extension from VS 2012 wouldn't work;
so I hunted down the Roslyn keys in my registry for VS 2012 and was
able to kinda figure out what was going on. After a bit of futzing
around, I finally got it working, so here's the instructions for
whoever might care to try [be warned, I'm sure this isn't supported by
MS, I take no responsibility if something happens to mess up your
computer, and so forth ;)].
Basically it was a matter of
copying some registry keys with slight modification copying some files
and this one is annoying but oh, well] there's a file you have to
change the datestamp on (I did it by opening the file in Notepad++ and
saving it out.) If you don't already have VS 2012 or you don't have
the Roslyn CTP installed you'll need to get the files somehow, and I'm
not sure if there are other registry settings needed or not, but I
imagine if you just manage to get the files out of the CTP distro it
would be enough... No guarantees of course.
Not-Instructions-Just-An-Explanation-Of-What-I-Did-I-Am-A-Trained-Professional-...-Or-Something
;)
copying some registry keys with slight modification; I replaced '11.0' with '12.0' in the keys and values, you might need to change
the paths too if you didn't install Visual Studio in it's default
location. (also posted to pastebin.com/XeP5ai8F )
Save this as a .reg file and open it to import the new keys easily:
Windows Registry Editor Version 5.00.
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\InteractiveWindows\0] "ContentType"="Roslyn C#"
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\InstalledProducts\Roslyn] ""="Microsoft Roslyn CTP" "ProductDetails"="Microsoft Roslyn CTP"
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Packages\{c5edd1ee-c43b-4360-9ce4-6b993ca12897}] "Class"="Roslyn.VisualStudio.CSharp.Repl.CSharpReplPackage" "CodeBase"="C:\\Program Files (x86)\\Microsoft Visual Studio
12.0\\Common7\\IDE\\Extensions\\Microsoft\\Roslyn C# Interactive Window\\1.2.20906.1\\Roslyn.VisualStudio.CSharp.Repl.dll"
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Packages\{f5199a4e-6a60-4f79-82e9-fc92a41c4610}] "Class"="Roslyn.VisualStudio.InteractiveWindow.InteractiveWindowPackage" "CodeBase"="C:\\Program Files (x86)\\Microsoft Visual Studio
12.0\\Common7\\IDE\\Extensions\\Microsoft\\Roslyn Components\\1.2.20906.1\\Roslyn.VisualStudio.InteractiveWindow.dll"
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\ToolWindows\{2d0a56aa-9527-4b78-b6e6-ebe6e05da749}] "Name"="Roslyn.VisualStudio.InteractiveWindow.VsInteractiveWindow"
copying some files; basically just need to copy the files mentioned above to the locations mentioned above; I just copied the
'Common7\IDE\Extensions\Microsoft\Roslyn C# Interactive Window' and
'Common7\IDE\Extensions\Microsoft\Roslyn Components' folders from my
11.0 install to my 12.0 install. easy peasy.
and yeah... there's a file in the aforementioned 'Common7\IDE\Extensions' directory called
'extensions.configurationchanged'; I couldn't get things to take, then
I noticed that file. so, as mentioned, I just opened in Notepad++ and
saved back out; I think I had to make a change to the file, so I added
a space. kinda felt kludgy, but I guess it beats VS taking longer to
load due to having to scan the Extensions every time you open it up.
So, that's it! Worked for me, I hope someone else may find this
useful, as it probably took longer to post this than it did to
actually get it working in the first place. ;) It's possible I missed
a step in here somewhere, since I had made a few other attempts before
I found the 'changed' file, so I could have possibly twiddled another
bit somewhere that was necessary that I don't remember. Should be a
good start tho.
I haven't tested it out fully by any means but it shows up in the
'View > Other Windows' list, it opens up just find, and it looks like
Intellisense is working too. Good luck and great code to all! :)
--- Chelle L.
You could also use LinqPad. You can use it to test C# code. It has built in support for loading DLLs and Nuget Packages. Its what I use personally and I love it.
It has a free version, but the paid version has intellisense and debugger
C# interactive finally arrived to VS 2015... You may need to install vs2015.1 to get it..
http://blogs.msdn.com/b/visualstudio/archive/2015/10/08/visual-studio-2015-update-1-ctp.aspx
Good luck... and happy interactive coding!
IWIH describes how to install it and which prerequisites you need.
Let me give you some
Additional information:
After you have installed VS 2015 and its updates (update 3 KB3165756 patch has just arrived) you can bring C# interactive to your screen as follows:
Either via the menu
View -> Other Windows -> C# Interactive
Or press Ctrl + Q and type into the quick launch box:
C# interactive
which allows you to click on View -> Other Windows -> C# Interactive with the mouse.
Afterwards, you have the C# Interactive beneath the error list. Here is an example how you can use it:
Quickstart:
To get help in this window, type #help and press enter.
To execute a statement, simply press ENTER. To type in multiple lines, press SHIFT+ENTER for each line, and for the last line press ENTER to execute the entire statement.
To print the values of a variable, type its name and press enter (in the screen shot, I have done this for variable q)

Analog of Visual Studio Solution for my application

I would like to make an analog of Visual Studio Solution for my application.
I mean to make a file similar to Microsoft Visual Studio Solution file (.sln), which includes links to all the other solution files.
Can anyone link to an article on this topic? I could not find anything about it.
If you need to build a series of Visual Studio solutions, then you need a build tool.
The two most commonly used in the .NET world are
MSBuild (reference: http://msdn.microsoft.com/en-us/library/dd393574.aspx)
Nant (reference: http://nant.sourceforge.net/)
(It's not clear what you're asking, you may wish to clarify or give an example.)
I didn't really understand what you mean, but it seems that you need a building system, like CMake (www.cmake.org).

C# Command Line Building

the book I'm reading went briefly over command line building, specifically controlling the linker.
But any class and .cs file containing classes or resources seems to link just fine if they reside inside my project, can I just ignore the command line builder for now until I'm more profficient in C# or is this something I need to know right now?
CommandLine builder using csc.exe in my knowledge is not used by even experienced professionals. Everyone goes the route of Visual Studio latest versions and it is safe to ignore commandline building.
But you can try and understand how it works. Because, in the end this is the one which is used by your GUI tools like Visual Studio to do the build.
I would generally say it is worth knowing how to use the command line building, but it is not a necessity. I started off just using Visual Studio and wasn't even aware of command line building for C#. However, since I learned to use it and write Command Script files to execute it, I actually use it fairly often - especially when working on large projects that have multiple dependencies in need of building. In that situation, it saves opening multiple Visual Studio instances.
Agreed with Muthu. Building via CSC.exe is good option and works for simple setups or for learning, but if you have a complex solution structure in Visual Studio using inter-project dependencies, post build events, etc. its best to just invoke the Visual Studio build call itself via the command line. The command is devenv.exe and you'll find lots of documentation on it.
If you are trying to learn C# complier/linker innards maybe you'll be more interested in Project Roslyn from Microsoft as they try to open the "black box" of the compiler.

VS2010 add-in custom menu item in files of Solution Explorer

I need to create a custom menu item for Visual Studio 2010 Add-in in C#, but I have had no luck in finding a solution for my needs.
I am aware that there was a similar post (Visual Studio Add-In - adding a context menu item to solution-explorer), but it did not help, as the blog follows the process through the integration package, and the video is done through VB. I had attempted to convert the VB syntax to the C# syntax, but about half way through the video, the Add-in methods has significantly changed from 2005 to 2010, as some of the methods have removed or changed.
Is there any good tutorials on making a custom menu item on the Solution Explorer in the lastest Visual Studio in C#, and is there a good website that could be used as a reference for looking over the VS add-in API? I've used Microsoft's main website, however it is confusing and wordy, which is difficult to understand and find the methods, properties, or commands that I am looking for.
Any help would be appreicated, Thanks in advance.
what are you writing? a number of cool add-ons already exist that might solve your problem..
such as vs 2010 Pro Power Tools
I don't know anything about it but you might want to check out MME MenuManagerTemplate and the sister project on CodePlex Managed Menu Extensions
Looks like the majority of the code is in the project on CodePlex so you could see how that project is implemented.

Categories

Resources