.net - Passing a TFS Workspace object to c# code from Powershell? -


i working on creating powershell scripts create easier maintain build process in tfs 2013.

part of process requires number of sql compares run update scripts.

what i'm trying use 1 of our old custom build activities (from tf 2010), looked reasonably easy convert c# code file use within powershell. needed post build / pre unit test step.

i'd make upgrades available unit tests, of db based integration tests not upgrading until following build.

the issue is c# script requires tfs workspace, , i'm not sure how or instantiate properly. build activity using tfs code model, had inarguments properties, , handled of this.

i've changed below run command in cut down c# example below:

using system.io; using system.text.regularexpressions; using microsoft.teamfoundation.build.client; using microsoft.teamfoundation.build.workflow.activities; using microsoft.teamfoundation.versioncontrol.client; using system.activities; using system; using system.collections.generic; using system.linq;   public class updateandcheckinnewscripts {     workspace workspace {get; set;}      public updateandcheckinnewscripts(workspace workspace)     {          this.workspace = workspace;      }      public void execute(string versiontoupdate, string sourcesdirectory, string binariesdirectory)     {           //... stuff scripts - ommitted...            //copy on previous script            file.copy(projectcreatefilepath, projectfinalpath, true);            //checkin project create script           workspace.checkin(workspace.getpendingchanges(projectfinalpath), "build agent", "my checkin",  null, null, new policyoverrideinfo("auto checkin", null),checkinoptions.suppressevent);     }      private static void checkinscript(string upgradeholder,             string filepath, string sourcesdirectory, string upgradereplacementtext, workspace workspace)         {             string file = sourcesdirectory + @"\\yyy\xxx\upgrade.csproj";              //checkout project file <-- how create workspace pass  object?              workspace.pendedit(file);              workspace.pendadd(filepath);             // ... other code      } } 

i want avoid outright rewrite of step if possible, open ideas. wanted move away customising default xaml build definition in tfs 2013. i'm taking advice link starting point using .net assemblies in powershell:

http://ruudvanderlinden.com/2010/10/19/running-inline-c-with-custom-assemblies-in-powershell-2-0/

i want know how tfs workspace object current build this, , how instantiate.

i think ps script might this:

# assume i've run sql comparison, create upgrade script , backups needed....  # assuming assembly , custom references required have been added, here...  $tfworkspace = ??? #not sure here add-type -typedefinition $source #assume $source above c# source. $scriptingobject = new-object updateandcheckinnewscripts($tfworkspace) $scriptingobject.execute($buildversion,$sourcelocalfolder,$bindirectory)  #continue custom script... 

i think have 2 options:

  1. instantiate workspace object within c# code somehow.

  2. instantiate object in powershell , pass instantiated object.

if can me either option, or other idea, appreciate it.

i ended using powershell scripts, mentioned microsoft development site: https://msdn.microsoft.com/en-us/library/dn376353.aspx .

i combined tfs power tools, , used add-tfspendingchange , new-tfschangeset cmdlets, used tfs api .net objects more control needed.

i did away using our original custom build activities, did customise build definition, allow more powershell scripts called @ more stages of tfs 2013 standard template.

all can powershell extremely powerful , worth effort learn, , did pretty needed our build process.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -