PowerShell is now open sourced and can run on Linux.
Azure PowerShell depends on full .NET Framework, so it can't run on Linux now.
However, preview version for .NET Core is released and I tried it.Read more
Visual Studio Team Services has an API, so we can queue and cancel build via API.
Here is an API about the build.
Microsoft provides four NuGet libraries for VSTS API.
Microsoft.TeamFoundationServer.Client is the library to execute build operation. However, it's hard to use. I write sample codes for queuing and cancelling build.
Here is a sample.
QueueBuildAsync, which is a method to queue a build, has the
Build object as a parameter.
Build object has many properties. However, there is no document which property is required. I found
Definition.Id (id of build definition) and
Project property are necessary after several tries.
Next, I'd like to cancel the queued build from C# code. What do I do? There is no API in the list. "Delete" method is not the API for cancelling but for deleting the completed build itself.
The answer is executing "update" method. We should update the queued build status to "cancel".
We should execute two or more API calls to queue or cancel build. That's the way to execute them from C# code.
I'd like to get the information of remote session source at the destination server with this function*1.
It can be written by C# with DllImport. The value of
It takes some doing because the structure of
ppBuffer is changed depending on the specified value in
WTSInfoClass. Here is a struct when
If you get all the sessions except itself, you can use this function.
*1:It seems OK for launching app with UAC elevation
I use PSCmdlet binary module code with C# in order to automate operation on Windows Server. Development with C# and execution speed are the pros for me. However there are issues I can't ignore. I will describe these issue and I wish PSCmdlet binary module solve these issues in the near future.
If I call
async method or Rx Observable method in Cmdlet and call
Write-Object after await, errors like below sometime occur.
The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and only from that same thread. Validate that the cmdlet makes these calls correctly, or please contact Microsoft Support Services.
This is due to SynchronizationContext.Current is null in Cmdlet class.
To solve this, one idea is providing custom SynchronizationContext.
AwaitablePSCmdlet is a good solution by sunnyone.
Another idea for using Rx is implementing producer-consumer pattern with BlockingCollection.
The assembly binding is sometime required when I use 3rd-party library in Cmdlet class
In my case, Google APIs Client library is the case. I must configure in app.config as below.
<?xml version="1.0" encoding="utf-8"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-22.214.171.124" newVersion="126.96.36.199" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
However, it is difficult to configure assembly binding in PSCmdlet binary module. Here is a stackoverflow thread about this.
To solve this issue, we should configure GAC and powershell.exe.config. But it is hard to accept because it influences the entire operating system. I'd like to configure separately for each module or process, but I can't find any solution so far.
This is the same issue of previous one as in terms of app.config. If I want to provide configuration to Cmdlet from app.config as well as Console Application, it is difficult to configure. Only global powershell.exe.config is effective for configuration.
To configure appdomain's configuration is one solution. But I worry about by-effect in appdomain. So, in my case Cmdlet receives app.config path and parse xml and pass configurations to logic class as below.
I understand this solution is only valuable if logic class can receive configuration directly (without ConfigurationManager).
These 3 issues are critical for me to use PSCmdlet binary module. However PSCmdlet is necessity for automating in Windows Server. I will approach better solution for these.
OpenForPSCmdlet helps debugging your Cmdlet binary module writing C# or VB.
After install this VS extension, you can right click "Open for PSCmdlet" in your Cmdlet class.
Then run build and open PowerShell console with Importing your Cmdlet module.
In the latest version, VS attaches PowerShell console process and you can debug directly.
This extension is opens source. Your comments and requests are welcome.
Failed to save quote. Please try again later.
You cannot quote because this article is private.