TFS 2010: run powershell script stored in source control - powershell

We've started using TFS2010 over at the company I work at. We create e-commerce web applications (shopping sites). I'm creating a custom template to deploy web projects after a build using a build template.
I've looked at the web deploy tool, but MSDN seems to indicate that it can only do initial deployments, and I need to be able to do incremental deployments with the same script.
I'm thinking of using the invokeActivity activity in the template to use powershell to do the job by specifying an FTP script which automatically copies the output of a build to a designated FTP site and then runs the SQL (upgrade) scripts, if needed by using SSH or s powershell remoting interactive session. (possibly specified in a separate SQL script)
There is some unknown for me which I can't get clear through the use of google:
When queuing a build, will I be able to let the user specify a script present in source control ( e.g. $(source)\scripts\ftpscript.ps1 ) as the script which is to be used? Will powershell be able to access/use that file? or should I copy it to the build directory and specify when I run it? (I don't know how to set up the template to get files from source control, so a pointer to some helpful info how to do that would be very much appreciated)
If the previous just doesn't work at all, could I create a folder \scripts\ in my website project, commit that to source control and then use BuildDetail.DropLocationRoot & "\scripts\" as the location for the script and fore a copy of the script files by enabling the force copy option?

To run a PowerShell script I think you can use the InvokeProcess activity which would trigger something like this:
%windir%\system32\windowspowershell\v1.0\powershell.exe "$(SolutionRoot)\test.ps1
And yes, you can reach a script file present in source control using the "SourcesDirectory" keyword.

Related

Copying files from Unix to Windows based on parameter

I run some control-m jobs which generate files and places in UNIX box under various folders.
These files need to be sent to different users who don't have access to the system.
Each time, I have to copy these files from the Unix folder (based on which control-m job was run) to my local directory and then send those to the users.
I am looking for a way to automate this. I want to create an interface where users can specify parameters (Job names), which in turn will copy the file from the particular folder on Unix to a location user has to access to.
The way I think I might have to approach this problem is -
Share a directory on any Windows virtual machine which everyone has access to. (This will be my landing zone)
Create a script which transfers files from various folders on Unix to Windows directory, based on the parameters that are being passed.
Create an HTA interface where users can specify parameters, which in turn will trigger the script and transfer the file, user is looking for, to windows directory
I am not a programmer but I would like to develop something which will make everyone's life easier.
Could someone please advise if this approach is correct or if this can be achieved in a better way.
Moreover, which language will be a good choice to write this script in. I know a bit of shell scripting and PowerShell. Willing to learn anything else if that solves my problem.
Please advise.
Here is one solution:
Obtain empty Windows server
Install chocolatey
cinst winscp (to copy files)
Use https://github.com/tomohulk/WinSCP to automate file copy via posh script. Provide adequate parameters for it.
cinst rundeck --params /Service to provide graphical interface for users in web
Manually create rundeck job and expose parameters for users so they have nice web GUI. You can let users specify folder or let them choose from the list.

Any way to run commands/script after VS2015 Publish wizard has copied files to output?

I have a very simple Windows service project I want to deploy to a server using Visual Studio 2015. I can successfully deploy using the Publish wizard (right-click on project -> Publish and deploy to \\myserver\c$\somepath\), but I need to 1) stop the service before publishing (so that the executable can be replaced), and 2) restart the service after the files have been copied.
I know how to start/stop services from the command line, and this answer provides a way to do it directly in a build action. However, I can't seem to find a way to execute any action after VS has copied the files to the output directory on the server.
For example, I have tried adding the following to my .csproj file without luck:
<Target Name="Mytarget" AfterTargets="AfterPublish">
<Warning Text="After AfterPublish" />
</Target>
Mytarget executes before VS actually copies the files to the server, so evidently, I can't hook onto AfterPublish. I've also tried PipelinePreDeployCopyAllFilesToOneFolder, CopyAllFilesToSingleFolderForPackage, and MSDeployPublish without luck (these don't seem to execute at all).
My end goal is to allow more-or-less one-click updating of the service, without having to log on to remote desktop and run a script manually after each update.
Is there any way I can have VS automatically execute an action after publishing a Windows service project to a server?

How do I generate a pubxml file for Azure App Service like the Visual Studio 2015 UI?

I have a simple web application in Visual Studio 2015.
With the Azure SDK installed, when I right-click the project and select Publish, I get a UI that allows me to select Microsoft Azure App Service as a publish target.
If I sign in and walk through the wizard, I ultimately end up with .pubxml and .pubxml.user files in my project that have the user names passwords, deployment endpoint, etc. that I need.
I am looking for a way to do this from the command line (ideally with PowerShell cmdlets for Azure, but calls to MSDeploy.exe or MSBuild.exe would be just fine).
Msbuild(Msdeploy) does not have related argument to create .pubxml and .pubxml.user, if want to use command line to achieve, you need to create a custom task, which create the xml by using code (C# or other). And you need to know the xml structure and related content.
About custom task, please refer to:https://blogs.msdn.microsoft.com/msbuild/2006/01/21/how-to-implementing-custom-tasks-part-i/
About create xml via c#, please refer to:https://msdn.microsoft.com/en-us/library/ff604982.aspx

How to run PowerShell remotely on Azure Website

Problem
I have website hosted on Azure as a Azure Website (not in a separate virtual machine).
I am going to create job that will run systematically, crawl and index site content.
I want to be able to run PowerShell on my PC which will work with remote date and show progress and result on my PC.
Also I want to create reports on PowerShell. As I do not have dummy boss that needs Excel reports in order to understand data. PowerShell is more convenient for IT-oriented person like me.
Idea
I have some idea and need validation from community.
Is it a good idea to create PowerShell module DLL, add as reference to Web Application project?
In this case I may be able to connect to site machine remotely (not sure) import module and work with it.
Web Jobs now natively support PowerShell scripts. You can upload a zip file containing a .ps1 file and it will be executed without further configurations.
Have you tried using the Kudu powershell interface? It lets you run powershell commands on your site directly from the browser
You can find it at:
https:// [yoursitename] .scm.azurewebsites.net/DebugConsole/?shell=powershell
You'll need to login with your ftp user name and password

Custom action after ClickOnce deployment / publishing

How can I run custom script which will upload ClickOnce deployment files to a web-server (in my case Windows Azure Blog Storage) right after publishing? Is it possible to modify MSBuild file in some way so it would run custom script right after ClickOnce published files into a local folder?
Yes, you can hook to build process using various technics:
pre and post build actions ( from visual studio project properties menu). It's actually exec task hooked into your project file
you can override your DependsOn property for concrete target and append execution of your own target (pre-Msbuild 4.0 way)
you can declare your target and hook with AfterTarget\BeforeTarget attributes (Msbuild4.0 way).
As for uploading something to blob - you can use Exec task in your own target to upload or use whatever tool\script you usually use to uploading files to website\Blob storage.
NB: You could clarify your question with following points (if you need more concrete answer) :
what kind of build process you are using - build from VS, CI server with custom msbuild script, CI server that building your sln file etc
what kind of script\tool you want to execute to upload build result.
do you know the name of last executed msbuild target, after which you want to fire your tool.