Visual Studio add custom command to run in Package Manager Console? - visual-studio

I am trying to create a button which will automatically run few powershell commands which are imported in nuget package (tools in nuget package)
I found out how to add custom button in this question: How can I add a custom command to Visual Studio?. But I cannot find out how to run from this command in package manager console.
So is there a way to add custom command button to visual studio, which will start and run command in package manager console?

Using a custom command described by link, you can run only external tools. In your case, you can run NuGet command line utility. First, you need to download nuget.exe. Then you have to add a custom command, arguments for it and initial directory in External Tools dialog. You can use solution variables (e.g., $(ProjectFileName), $(SolutionDir)) for arguments and initial directory fields. You can use bat file to run few commands.
Unfortunately, the NuGet command line utility has fewer features than package manager console. I don't know, is it enough of these features to solve your issue?
To use all features of NuGet and to integrate into Visual Studio, you can implement your VSPackage. From VSPackage you can add at any place of Visual Studio the custom command (as a button or menu item). When the command launch (user clicked your button), you can call any method of NuGet API inside Visual Studio. This way requires time to develop and not so simple.

Related

Create own Package Manager Console commands?

I'd like to include custom Package Manager Console commands with my NuGet Package. Just like EF-Core is doing recently to generate the context for example.
How can this be done without having to use the default folder "... Documents\WindowsPowerShell\NuGet_profile.ps1"?
I want to generate classes via console so I do not have to develop a Visual Studio extension for it.
Thank you!
You would pack .pds1/.psm1 files into a tools directory inside the NuGet package. Which are automatically available inside the Package Manager Console (the tools folder will be added to the PATH environment variable).
You can download and inspect the Microsoft.EntityFrameworkCore.Tools for reference, since this is the package that provides the Entity Framework Core commands.

Create Package Manager Console Command

I don't know much about NuGet, I only used it a few times to download a few things into my Visual Studio projects. I need to make a command, that can be entered into the Package Manager Console in Visual Studio, that would then create a solution with a variable number of C# projects in it (the variable would be passed as an argument in the command). I've seen it done before, but I have no idea where to start.
You could look at how Entity Framework does it - http://entityframework.codeplex.com

Automate the renaming of classes in Visual Studio 2013 using the SDK and VS API

How do I rename classes with an API call, from within a Visual Studio 2013 plugin we are building?
We are already adding files and generating code to a project from within the plugin, but how to can we open the rename refactoring dialogue?
The plugin is an entity editor for a custom ORM system. Here is a screenshot
You can execute any command such as "Refactor.Rename", etc. using either DTE.ExecuteCommand("mycommand") or by command guid and id:
HOWTO: Execute a command by Guid and Id from a Visual Studio package.
http://www.visualstudioextensibility.com/articles/packages/
To learn the command names go to "Tools" > "Customize..." and then "Keyboard" button.

Add custom nuget feed from the Package Manager Console (PowerShell)

Is there a way to add custom nuget feeds without going through the GUI? I know I can open the "Manage Nuget Packages" dialog, go to Settings, and add from there. I'm looking for a way to add a feed through PowerShell.
You could modify nuget visual studio extensions configuration file (located by default at C:\Users\%UserName%\AppData\Roaming\NuGet) with PowerShell

Visual Studio Deployment Project: Dependencies in the installation directory

I would like to install an add-on to an application. The application does not create a registry key that I can use to locate it. Therefore the user should specify the directory of the program, the installer should check whether the programs files are in that directory and only if the main program is installed to that directory, install the add-on to that directory.
Can this be done with Visual Studio's Deployment Project?
As far as I can see, the VS Deployment Project checks for dependencies only when starting the installer, not after the installation directory has been specified. Id like to get a second opinion before starting to use more advanced deployment tools.
No, this is not supported by Visual Studio.
What you need can be done by using a custom action on the "Next" button of the folder path dialog:
http://msdn.microsoft.com/en-us/library/aa368322(VS.85).aspx
This custom action can check if the required files exist and set the result in an installer property. This property can then be used to condition the "NewDialog" control event which shows the next dialog. It can also be used to condition another custom action which shows a custom error message.
If you want a free solution you can try WiX. You should be able to define the custom action and DoAction published control event.

Resources