I created a default ClassLibrary project in visual studio. Then I added an basic class that has one method in it.
Then I opened Package Manager console in visual studio. And I run standard Regex replace method on it and it works. Then I try to run my own replace method but it didnt work. Is there any way to run user defined methods on Package manager console or is it only allowed by core libraries on windows ?
PowerShell needs to load the type first before it can call it.
Add-Type -Path c:\test\ClassLibrary1.TestClass.cs
[ClassLibrary1.TestClass]::Replace("testx","x","y")
You could also put the add-type call into your NuGet_profile.ps1, and load your DLL if there will be multiple classes you need to call.
Related
When I try to use an extension method in the Immediate or Watch windows, I get the following error:
{method} is not a member of {class}
I'm using Visual Studio Community 2013 Update 4, but the issue exists on multiple PCs here, running varying versions of Visual Studio 2013 and 2015.
It makes no difference whether the extension methods come from the .NET BCL, or are defined in our project. The code itself compiles and runs successfully; the issue is only in Immediate and Watch.
I tried setting all projects to framework 4.5.1, and using the x86 configuration, without result.
Adding Imports System.Linq at the beginning of the code file makes no difference (which makes sense, as System.Linq is already globally imported (Project properties -> References -> Imported namespaces)).
What else can be done?
In any context where System.Linq isn't imported you can call the extension methods as normal static methods instead. So for example, the following did not work for me in the QuickWatch window (where actualVariables is a List):
actualVariables.Select(x=>x.Identity.DisplayName)
Change it to this form and then it works:
System.Linq.Enumerable.Select(actualVariables,x=>x.Identity.DisplayName)
I'm trying to create a NuGet package that contains both managed (assemblies) and unmanaged (native DLLs) binaries, and also support several platforms (x86, x64).
To have a better understanding of how to handle that properly, I had a look at several packages that share similar requirements, published on the official nuget feed. One of them is Microsoft.SQLServer.Compact.
Seeing what is done in the Install.ps1, Uninstall.ps1 PowerShell scripts and in the VS.psm1 PowerShell module is very helpful.
The VS.psm1 module contains definitions for a few functions allowing to control Visual Studio from within the package installation script (notably, through the $dte object). These functions are based on the Visual Studio Object Model, which I don't know yet and that is (in my opinion) not very well documented.
I was wondering if you know about a PowerShell module that would allow to easily handle the Visual Studio Object model from a NuGet PowerShell script. Alternatively, any pointer to books, blog posts, articles, ... showing a few examples about how to properly use that object model from PowerShell would be very welcome. The only examples I have found on the net usually illustrate very basic functionality.
Also, if you know about other NuGet packages dealing with both managed and unmanaged libraries that I could use as examples, that would be nice.
I could of course start from what I have seen in the files mentioned above and roll my own module, but I would rather concentrate on my package itself if there is already something available.
Thanks for your help.
Take a look at StudioShell. It is a system for bringing PowerShell automation into VS.NET and is available as an installer but also as a NuGet package to enable the sort of scenario you describe. PluralSight course "Everyday PowerShell for Developers" course has an intro to the system and there are some examples on the project site.
This may not be directly related to your post. The Package Manager Console in my opinion should be called the PowerShell Console. It gives you full access to the DTE.
I have a trivial example of using it, pure PowerShell, no t4 or extensions, to add several files to Visual Studio to automate adding Command Pattern classes.
http://github.com/jefflomax/vs-package-manager-console-cmdlets
We could certainly use a more complete library of PowerShell cmdlets to handle simple Visual Studio tasks in this environment.
I am creating a small program over entityframework which allows to edit the POCOs with a UI. as part of the process i would like to call the "add-migration" command from my code to save the interaction of the rest of the programmers with the program manager console. is it possible at all?
thanks
Add-Migration cmdlet is defined in separate EF 4.3 Powershell assembly used by Package manager console. This assembly references a real EF 4.3 assembly. The core logic exposed from that assembly is ToolingFacade class from System.Data.Entity.Migrations.Design namespace. The exposed logic involves retrieving database and pending migrations and scaffolding a new migration but PowerShell assembly contains the execution workflow and creates bridge between EF, PowerShell and Visual studio (adding classes to your project) - this is what you must reverse engineer and reimplement in your tools.
Edit: You can also try to run MigrationCommands.AddMigration directly from PowerShell assembly.
How do I get an instance of a currently running Visual Studio instance ?
I need to access Visual Studio object model (DTE) outside of the Visual Studio.
I want to run a nuget install script from powershell ise - to be able to better understand what the script is doing and why it's not doing what i expect
So I want to feed in all the parameters that install.ps1 takes in
param(
[Parameter(Mandatory=$true)] [string] $installPath,
[Parameter(Mandatory=$true)] [string] $toolsPath,
[Parameter(Mandatory=$true)] $package,
[Parameter(Mandatory=$true)] $project
)
It's easy to set the strings parameters, gowever
project and package are the tricky ones
I do have access to nuget cmdlets. I followed this post to achieve that.
So I import-module PackageManagement.Cmdlets.dll
That all works fine
now when I attempt something like
$project = Get-Project -name SmartCom.Registration.Logic
I get this message "A project must be open to run this command." so I guess I first need to hook into vs via DTE and open a solution and then load a project in order for this to work?
I know that there are things like PowerConsole that hook up with vs automatically, but in this case I want it to work outside of the vs so i can debug it with powershell isa
Any ideas?
Assuming Visual Studio is running (and there's only one instance) then you can do this:
PS> $dte = [runtime.interopservices.marshal]::GetActiveObject("visualstudio.dte")
PS> $dte
Name : Microsoft Visual Studio
...
Hope this helps.
The post you linked to uses SharpDevelop to allow the use of NuGet PowerShell cmdlets outside of Visual Studio. It has no dependency on Visual Studio so I do not believe opening an instance of Visual Studio will help you.
The error is being displayed because there is no solution currently open. To open a solution you can use the set-project cmdlet:
set-project MyProject d:\Projects\MyProject\MySolution.sln
Then you should be able to call the get-project cmdlet.
There is the Deploying COM Components with ClickOnce article in MSDN that says that native DLLs also could be referenced:
To add a native reference, use the Add Reference command, then browse
to the manifest.
So, I'm trying to reference Skype4COM library. I've generated a manifest using mt
tool. But when I try to reference this manifest, VS says me:
.
What am I understand or I'm doing wrong?
You are mixing up deploying with building. Adding a reference requires a type library or a DLL that contains a type library embedded inside the DLL. Skype4com.dll has one but it has a problem which prevents it from being added through the Add Reference dialog.
Use the Visual Studio Command Prompt from the Start + Programs menu. Use cd to navigate to the correct directory and type tlbimp skype4com.dll. You'll get a warning that you can ignore as long as you are running 32-bit code. Go back to VS and use Add Reference, Browse tab and select the generated SKYPE4COMLib.dll file.