-
Notifications
You must be signed in to change notification settings - Fork 21
Package Manager Console Powershell Reference
- Add-PrigAssembly(padd)
- Find-IndirectionTarget(pfind)
- Get-IndirectionStubSetting(pget)
- Start-PrigSetup(pstart)
- Remove-PrigAssembly(premove)
Creates the Stub Settings File for the specified assembly on the Package Manager Console or the Prig Setup Session.
Add-PrigAssembly -Assembly <String> [-Project <Object>] [<CommonParameters>]
Add-PrigAssembly -AssemblyFrom <String> [-Project <Object>] [<CommonParameters>]
Add-PrigAssembly -ReferencedAssembly <Assembly> [-Project <Object>] [<CommonParameters>]
This command adds the Stub Settings File that sets up the Indirection Stub Settings for specified assembly to a project on the Package Manager Console or the Prig Setup Session.
Target project is the value that is selected as Default project:
on the Package Manager Console. The Stub Settings File is named like <assembly name>.<runtime version>.v<assembly version>.prig
. After the file is added, you will get the confirmation message that the project has been modified externally, so reload the project.
Also, you can't add the setting file for same assembly. If you want to add it again, execute Remove-PrigAssembly
command once to remove the setting file.
A display name recognizing uniquely an assembly. Use this parameter if adding the Stub Settings File for a GAC registered assembly. If it can't recognize uniquely, the error "Ambiguous match found" will be occurred. So, you have to specify a more detailed display name. You can also refer to the Assembly parameter by its built-in alias, "as".
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
A full path recognizing uniquely an assembly. Use this parameter if adding the Stub Settings File for a GAC unregistered assembly. Also, you have to change to the directory where specified assembly exists if using this parameter; otherwise referenced assemblies may not resolved. You can also refer to the AssemblyFrom parameter by its built-in alias, "af".
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
A referenced assembly object.
You can use this parameter only in the Prig Setup Session. If you specify this parameter in another environment, the error "Invalid operation is detected" will be occurred. For more detail, please see the help for Start-PrigSetup
.
You can also refer to the ReferencedAssembly parameter by its built-in alias, "ra".
Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
A EnvDTE.DTE
object that adds Prig Assembly.
This API supports the Prig infrastructure and is not intended to be used directly from your code.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
System.String, System.Reflection.Assembly
None
You can also refer to the Add-PrigAssembly command by its built-in alias, "PAdd".
C:\PS>Add-PrigAssembly -Assembly "mscorlib, Version=4.0.0.0"
This command adds the Stub Settings File for the assembly mscorlib
to the target project.
C:\PS>padd -as mscorlib
Ambiguous match found:
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
This is example that "You try to add the Stub Settings File for the assembly mscorlib
, but the error 'Ambiguous match found' is occurred". In this error, candidate assemblies are listed at the time. So, select again more detailed display name from them.
C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug>dir
Directory: C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2014/10/10 9:31 4096 DependentLibrary1.dll
-a--- 2014/10/10 9:31 7680 DependentLibrary1.pdb
-a--- 2014/10/10 9:31 4608 DependentLibrary2.dll
-a--- 2014/10/10 9:31 7680 DependentLibrary2.pdb
-a--- 2014/10/10 9:31 7680 DemoLibrary.dll
-a--- 2014/10/10 9:31 28160 DemoLibrary.pdb
C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug>padd -af (dir .\DemoLibrary.dll).FullName
This command adds the Stub Settings File for the GAC unregistered assembly DemoLibrary
to the target project. If you specify -AssemblyFrom
parameter, you have to execute this command in the directory that the target assembly exists like the example.
C:\PS>padd -ra $ReferencedAssemblies[0]
This command adds the Stub Settings File for the assembly mscorlib
in the Prig Setup Session. In the session, you can confirm the referenced assemblies of current project through the global variable $ReferencedAssemblies
, also you can pass it to Add-PrigAssembly
command as it is. For more detail, please see the help for Start-PrigSetup
.
Finds the targets to create the Indirection Stub Setting on the Package Console Manager, PowerShell or the Prig Setup Session.
Find-IndirectionTarget [-InputObject] <Object> [[-Method] <Object>] [-PublicOnly] [-IgnoreMockable] [<CommonParameters>]
This command finds the methods that are satisfied the search condition on the Package Manager Console, PowerShell or the Prig Setup Session.
About the search way, first, it enumerates the members that are satisfied the following conditions from the specified parameter as -InputObject
:
- a public member or a non-public member
- a instance member or a static member
- a only member declared at the level of the supplied type's hierarchy
- a constructor(containing a type constructor) or a method
- a non-abstract members
From them, it narrow the search to the results that are matched to specified the parameter -Method
. The string that is compared with -Method
is same as the string that is listed as the results this command invoked.
An array of type or an array of string that can be recognized as a type.
"The string that can be recognized as a type" means that Invoke-Expression ('[{0}]' -f $s)
- NOTE: $s is string - can evaluate to Sytem.Type
object. Therefore, you can specify the parameter like datetime
, system.reflection.assembly
, ([int])
and so on.
Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
A search condition for the methods. You can use regular expression.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
Omits non-public members from the search results.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
Omits mockable members from the search results.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
System.String, System.String[], System.Type, System.Type[]
None, System.Reflection.MethodBase, System.Reflection.MethodBase[]
You have to import the module Urasandesu.Prig
explicitly if you use this command on PowerShell directly. The module Urasandesu.Prig
is placed the directory tools
of the package directory by NuGet when you installed Prig. So, execute Import-Module
from there. By the way, this step requires a little labor. Using the Prig Setup Session would be more easier. See also the help for Start-PrigSetup
for more details.
You can also refer to the Find-IndirectionTarget command by its built-in alias, "PFind".
C:\PS>Find-IndirectionTarget datetime '(today)|(now)'
Method
------
System.DateTime get_Now()
System.DateTime get_UtcNow()
System.DateTime get_Today()
This command finds the members that contain the string today
or now
from the type System.DateTime
.
PS C:\>$asmInfo = [System.Reflection.Assembly]::LoadWithPartialName("System.Web")
PS C:\>$asmInfo.GetTypes() | ? { $_.Name -eq 'httpcontext' }
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False HttpContext System.Object
PS C:\>$asmInfo.GetTypes() | ? { $_.Name -eq 'httpcontext' } | pfind -m 'get_current\b'
Method
------
System.Web.HttpContext get_Current()
In this example, first, it finds the types that is named httpcontext
from the assembly System.Web
. Against the results, use this command, and find the members that are matched the regular expression get_current\b
.
C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug>ipmo ..\..\..\packages\Prig.0.0.0-alpha10\tools\Urasandesu.Prig
C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug>$asmInfo = [System.Reflection.Assembly]::LoadFrom((dir .\DemoLibrary.dll).FullName)
C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug>$asmInfo.GetTypes()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False Foo System.Object
C:\users\akira\documents\visual studio 2013\Projects\Demo\Demo\bin\Debug>$asmInfo.GetTypes() | pfind
Method
------
Void .ctor()
This is the example that doesn't use the Package Manager Console but use PowerShell.
The Package Manager Console doesn't support nested prompt by its design. Therefore, there is the problem that it can never release the assemblies if it loaded the assemblies to analyze targets once. In the first place, the features that are used mundanely - such as autocompletion, commands history and so on - are less functionality than PowerShell's. I highly recommend that you always use PowerShell when analyzing the targets.
Gets the Indirection Stub Setting on the Package Manager Console, PowerShell or the Prig Setup Session.
Get-IndirectionStubSetting [[-InputObject] <MethodBase[]>] [<CommonParameters>]
This command creates XML tags that can be used as the Indirection Stub Setting for the target method on the Package Manager Console, PowerShell or the Prig Setup Session, and gets them.
The Indirection Stub Setting mean the tag that can be added to the Stub Settings File(*.prig
) that is set up by the command Add-PrigAssembly
. In particular, the tag is add
. You can insert it to between the tag <stubs>...</stubs>
of the file.
Note that you have to typically generate unique name, and set to the tag(its attribute name
and alias
) in the type the target method is declared. However, you can get easily such name by using this command.
These generated types are called Prig Type or Prig Type Introducer. Prig Type is a stub type to set the dummy method body as replacement target method, and Prig Type Introducer is the type that defines the identifier list to specify the target method. Their naming convention is similar to Microsoft Fakes's, but there is also a little different:
-
The namespace that the Prig Types are located is the original namespace +
.Prig
.
For example, the Prig Types for the types underSystem
are located at the namespaceSystem.Prig
. -
The prefix of the Prig Type is
P
(no conditions) orPProxy
(specified instance of a class).
For example, the Prig Type forSystem.DateTime
isSystem.Prig.PDateTime
. However, the Prig TypePProxyDateTime
isn't generated, because it is a structure. The Prig Type forSystem.Net.HttpWebRequest
isSystem.Net.Prig.PHttpWebRequest
. Also,System.Net.Prig.PProxyHttpWebRequest
is generated, because it is a class. -
The prefix of the Prig Type Introducer is
OfP
(no conditions) orOfPProxy
(specified instance of a class).
The difference between a class and a structure is same as Prig Type.
See also Code generation, compilation, and naming conventions in Microsoft Fakes.
The results are output as plain text, so I recommend that you use in combination with clip
command.
A array of System.Reflection.MethodBase
object which is target to get the Indirection Stub Setting.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
System.Reflection.MethodBase, System.Reflection.MethodBase[]
System.String
You have to import the module Urasandesu.Prig
explicitly if you use this command on PowerShell directly. The module Urasandesu.Prig
is placed the directory tools
of the package directory by NuGet when you installed Prig. So, execute Import-Module
from there. By the way, this step requires a little labor. Using the Prig Setup Session would be more easier. See also the help for Start-PrigSetup
for more details.
You can also refer to the Get-IndirectionStubSetting command by its built-in alias, "PGet".
PS C:\>pfind datetime _now | pget
<add name="NowGet" alias="NowGet">
<RuntimeMethodInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:x="http://www.w3.org/2001/XMLSchema" z:Id="1" z:FactoryType="MemberInfoSerializationHolder" z:Type="System.Reflection.MemberInfoSerializationHolder" z:Assembly="0" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/System.Reflection">
<Name z:Id="2" z:Type="System.String" z:Assembly="0" xmlns="">get_Now</Name>
<AssemblyName z:Id="3" z:Type="System.String" z:Assembly="0" xmlns="">mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyName>
<ClassName z:Id="4" z:Type="System.String" z:Assembly="0" xmlns="">System.DateTime</ClassName>
<Signature z:Id="5" z:Type="System.String" z:Assembly="0" xmlns="">System.DateTime get_Now()</Signature>
<Signature2 z:Id="6" z:Type="System.String" z:Assembly="0" xmlns="">System.DateTime get_Now()</Signature2>
<MemberType z:Id="7" z:Type="System.Int32" z:Assembly="0" xmlns="">8</MemberType>
<GenericArguments i:nil="true" xmlns="" />
</RuntimeMethodInfo>
</add>
PS C:\>pfind datetime _now | pget | clip
This is the example that is used in combination with Find-IndirectionTarget
. Search the members that are matched to the regular expression _now
from the type System.DateTime
, and get the Indirection Stub Setting. When confirmed that, it has no problem. So, copy it to clipboard.
Usually, paste it to the Stub Settings File thereafter.
Starts the Prig Setup Session.
Start-PrigSetup [-NoIntro] [[-AdditionalInclude] <String>] [[-EditorialInclude] <String>] [[-DeletionalInclude] <String>] [[-Project] <Object>] [<CommonParameters>]
The Prig Setup Session is a special PowerShell session to add the Stub Settings File and analyze target assemblies. In this session, you can access all information of the assemblies that are referenced from current project through the global variable $ReferencedAssemblies
.
Omits the introduction help that is displayed when startup the session.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
A referenced assembly name that is used as additional Include
.
This API supports the Prig infrastructure and is not intended to be used directly from your code.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
A referenced assembly name that is used as editorial Include
.
This API supports the Prig infrastructure and is not intended to be used directly from your code.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
A referenced assembly name that is used as deletional Include
.
This API supports the Prig infrastructure and is not intended to be used directly from your code.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
A EnvDTE.DTE
object that adds Prig Assembly.
This API supports the Prig infrastructure and is not intended to be used directly from your code.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
None
None
You can also refer to the Start-PrigSetup command by its built-in alias, "PStart".
PM>Start-PrigSetup
------- (The following commands are executed in new PowerShell window)
Welcome to Prig Setup Session!!
You can add the stub settings from here. In this session, you can use `$ReferencedAssemblies` that contains all referenced assemblies information of current project. For example, if you want to get the Indirection Stub Settings for all members of the type `Foo` that belongs to the referenced assembly `UntestableLibrary`, the following commands will achieve it:
PS> $ReferencedAssemblies
FullName
--------
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
MyLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
UntestableLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
PS> padd -ra $ReferencedAssemblies[-1]
PS> $ReferencedAssemblies[-1].GetTypes() | ? { $_.Name -eq 'Foo' } | pfind | pget | clip
PS> exit # Then, paste the content on the clipboard to the Stub Settings File(e.g. `UntestableLibrary.v4.0.30319.v1.0.0.0.prig`).
See also the command's help `padd`, `pfind` and `pget`.
Current Project: MyLibraryTest
WARNING: Change the Current Project from `Default Project: ` on the Package Manager Console if it isn't what you want.
In this example, start the Prig Setup Session from the Package Manager Console. When the Prig Setup Session is started, new PowerShell window is opened with the introduction help like the above.
PM>pstart -NoIntro
------- (The following commands are executed in new PowerShell window)
Current Project: MyLibraryTest
WARNING: Change the Current Project from `Default Project: ` on the Package Manager Console if it isn't what you want.
PS> $ReferencedAssemblies
FullName
--------
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PS> $ReferencedAssemblies | ? { $_.FullName -cmatch 'Con' }
FullName
--------
System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
PS> padd -ra ($ReferencedAssemblies | ? { $_.FullName -cmatch 'Con' })
PS>
In this example, start the Prig Setup Session without the introduction help when opened. Then, confirm the assemblies that are referenced from current project, choose System.Configuration
from those assemblies, and add the Indirection Stub Setting.
Removes the Stub Settings File for the specified assembly on the Package Manager Console or the Prig Setup Session.
Remove-PrigAssembly [-PrigAssembly] <String> [[-Project] <Object>] [<CommonParameters>]
This command removes the Stub Settings File that is added by Add-PrigAssembly
from a project on the Package Manager Console or the Prig Setup Session.
Target project is the value that is selected as Default project:
on the Package Manager Console. After the file is removed, you will get the confirmation message that the project has been modified externally, so reload the project.
A Prig Assembly name. If it can't recognize uniquely, the error "Ambiguous match found" will be occurred. So, you have to specify a more detailed Prig Assembly name. You can also refer to the PrigAssembly parameter by its built-in alias, "pa".
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
A EnvDTE.DTE
object that removes Prig Assembly.
This API supports the Prig infrastructure and is not intended to be used directly from your code.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
System.String
None
You can also refer to the Remove-PrigAssembly command by its built-in alias, "PRemove".
C:\PS>Remove-PrigAssembly -PrigAssembly mscorlib
This command removes the Stub Settings File for the assembly mscorlib
from the target project.
-
Home
- QUICK TOUR [SRC]
- FEATURES
- CHEAT SHEET
- PACKAGE MANAGER CONSOLE POWERSHELL REFERENCE
- COMMAND LINE REFERENCE
- APPVEYOR SUPPORT
- MIGRATION
- From Microsoft Research Moles [SRC]
- From Microsoft Fakes [SRC]
- From Telerik JustMock [SRC]
- From Typemock Isolator [SRC]