How to publish a Powershell Module to PowershellGallery with Appveyor? - powershell

Is there a way to add a custom powershell script into the appveyor build script to publish a module to powershellgallery? - The module source would be in the github repo.
If not, maybe it's possible within the appveyor web config itself?

I believe you can create script based Publish-Module command and insert it into right stage of build pipeline. For example if you decide to publish after test stage, it will look like this in YAML:
after_test:
- ps: Publish-Module -Name "MyDscModule" -NuGetApiKey "11e4b435-6cb4-4bf7-8611-5162ed75eb73"
Or in UI you need to go to Settings > Test > Auto > After tests script > PS and enter publish script.

Related

Post Build event that works on both Azure DevOps and Local PC

I have a VS2017 solution that Builds both locally and also on Azure DevOps.
I now need to run a Post Build script to run an EXE. I have this working on my local machine, but I guess there will be an issue with the Path to the EXE which has been added to the DevOps Library.
Note. The EXE is all installed on DevOps and runs fine from a Command Line Task - I just need it to run as a post build on one of the projects so that this project is ready to be packaged in the Installer SetUp project. (During a full Solution build).
This represents the Local Post Build script - How do I handle this on Azure, where the path will be different?
"C:\Program Files (x86)\{dir}\{app}.exe" -file "$(ProjectDir){file.txt}"
Any help appreciated. Thanks!
This represents the Local Post Build script - How do I handle this on
Azure, where the path will be different?
$(ProjectDir) is msbuild property, so it works on both Azure DevOps and Local PC. You only need to pay attention to the {dir} of the xx.exe.
My suggestion is to put the exe in solution folder (where the xx.sln file exists), then you can use script like "$(SolutionDir)\{app}.exe" -file "$(ProjectDir){file.txt}". The $(SolutionDir) and $(ProjectDir) can be recognized by msbuild. (It works for both local pc and online devops.)
Or you can put the xx.exe under root directory of your git repo, then use $(System.DefaultWorkingDirectory) as the path of your xx.exe, but it only works for online devops, it can't work on local PC. (Not recommended)

Invoking MsDeploy.exe manually in a Azure Devops

Background
As part of our deployment pipeline we are creating our deployment artifact, by running several .xdt transforms on our build artifact as well as adding several additional files.
As the last step before publishing, we would like to invoke msdeploy.exe to build a "custom" webdeploy package from a folder containing the wwwroot-content - (msdeploy command for creating custom package found in this question Web Deploy - How to create a package with selected items)
We are using hosted agents (win 2017).
We wish to deploy to an Azure AppService.
Question
Is there a task in Azure DevOps, that allows you to invoke MsDeploy.exe manually, such that we can create a custom webdeploy package, before we deploy?
Is there a task in Azure DevOps, that allows you to invoke MsDeploy.exe manually, such that we can create a custom webdeploy package, before we deploy?
I am afraid there is no such task to invoke MsDeploy.exe manually. We need invoke it by command line task, just like Daniel comment.
As we know, the default installation will place msdeploy.exe in:
C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe
To verify the msdeploy path on the hosted agents, I use a copy task with content **\msdeploy.exe:
Then use the Publish build artifacts to output the msdeploy.exe, I could get the result on the hosted agent vs2017-win2016 and windows-2019:
So, the the msdeploy path on the hosted agents vs2017-win2016 and windows-2019 is C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe. We could use command line task to invoke it.
Hope this helps.
Here is the exact CommandLine task that worked for me (without parameters though):

VSTS - Custom Build on Powershell and upload to Artifact to directory

did anyone have worked custom build on the powershell and upload the artifact to the VSTS directory.
I have configured Build Process on the VSTS agent, Build process all passed and i have artifact, we also need to encrypt the app, the process is on CLI, i have powershell script execute those tasks, but i couldn't able to upload that articats to VSTS directory,
his anyone have any idea how can i achieve this goal.
The tasks (i) button helps understand the directory you'll be working in the context of for a task.
In the instance of the Powershell task it will be working from the $(System.DefaultWorkingDirectory). If the powershell task is in version control use the ... button to select the powershell script you wish to execute.
Once your script executes you'll probably want a Copy Task to copy the file you just encrypted to $(Build.ArtifactStagingDirectory) something like this (obviously you'll need to modify the contents field so it copies the encrypted file from the powershell step):
Then you're ready to publish to Azure DevOps taking the contents of $(Build.ArtifactStagingDirectory) and making this an artifact for the build. In the below example this artifact will be called drop.
Hope that helps.

Error MSB4126: The specified solution configuration "release|any cpu" is invalid

I had setup the devops flow for one of my client application. It’s woking fine in build and release level. But after some days suddenly my build failed with the following error.
node_modules\uws\build\binding.sln.metaproj(0,0): Error MSB4126: The specified solution configuration "release|any cpu" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration.
Can anyone please tell me how to resolve this issue?
You can use PowerShell tasks to change the .sln file.
Assume if you want to build projects except a website project, then you can remove the website project info in GlobalSection of the .sln file.
Prerequisites:
Get the project ID you want to remove, the formate as ECF93D95-5096-497E-B4B8-83416DABB516.
Then add a PowerShell task before VS build task which build other projects. The script as:
git checkout $(BUILD.SOURCEBRANCHNAME)
(get-content "$(Build.SourcesDirectory)\relative\path\to\solution") -notmatch "{project_ID}.$(BuildConfiguration)" | out-file "$(Build.SourcesDirectory)\relative\path\to\solution"
Such as below example to remove the project ECF93D95-5096-497E-B4B8-83416DABB516 from .sln file:
git checkout $(BUILD.SOURCEBRANCHNAME)
(get-content "$(Build.SourcesDirectory)\ConsoleAppCore\ConsoleAppCore.sln") -notmatch "{ECF93D95-5096-497E-B4B8-83416DABB516}.$(BuildConfiguration)" | out-file "$(Build.SourcesDirectory)\ConsoleAppCore\ConsoleAppCore.sln"
After the VS Build task, you can add another PowerShell task to recovery the changed .slnas the same version in git repo. The script as:
git reset --hard head
For building websit project except other projects, you can use the same way to skip the project for building.
Note: for PowerShell task, please deselect Fail on Standard Error option.
I think the best option is to use multiple solutions which target group of projects together (Partitioned Solution)
Here is link to get more info about it
Partitioned Solution
Also I implement in many open source project, here one of them
Project on GitHub using Partitioned Solution
I had this problem once while using VSTS. I suggest you to use MSBuild arguments directly
Ho to add to MSBuild Arguments:
/p:Configuration=$(BuildConfiguration) /p:Platform="$(BuildPlatform)"
Note: leave Platform and Configuration empty

VSTS CI CD for desktop apps

How can I achieve CD (Continuous Delivery) for winform applications in VSTS (Visual Studio Team Services)? Currently this is what I have in my Visual Studio Solution file
1) A winform project
2) A Windows setup and Deployment project
So every time I build a winform project, I do the following steps (and I need CI / CD for exactly these)
1) Build Setup and Deployment project, which takes Build output of Winform project and creates and EXE / MSI
2) I take this MSI file and use NSIS to embed it inside EXE
3) I run SIGNTOOL from command prompt and digital sign the EXE
4) I upload this signed EXE to my website
Now how can I use CI / CD pipeline to automate the above or is it not possible for my case? I am confused. I can't find any material for winforms, all are for web apps.
Thanks
You will obviously need some sort of desktop deployment strategy. The easiest is to be using xcopy. Other alternatives include frameworks like ClickOnce, Windows Installer or Squirrel to name a few. I have a number of corporate apps that use Clickonce that I have deployed using vsts.
Now I am unable to understand how will VSTS help me with this?
Use VSTS to build the software first and include additional tasks to package your app. In my case, I use devenv.exe to generate ClickOnce packages, but you can include custom tasks by using powershell. The artifact of the build should now be the "packaged app".
Then use the VSTS deployment to copy the "package" to some kind of hosting server from where your users can download the package. That could be either a web server or a fileserver or any location appropriate for your deployment strategy.
In this context, VSTS is an orchestration tool. It helps to trigger actions for you.
See Deploy an agent on Windows to see how to setup an on-premise agent.
To build and deploy the way as you used in VSTS, you can use below steps:
Create a repository (Git or TFVC) and push your solution in the repository.
Add build/release definitions.
With CI build, enable the Continuous Integration in Triggers Tab. With CD deploy, enable Continuous deployment trigger in Pipeline Tab. The process for CI build and CD deploy, you can refer CI/CD.
Add related tasks in your build/release definition.
Build VS Installer task: build setup project with msi file.
Nsis Build Task: embedded msi file in exe.
Command Line task: to execute the signtool command. Since Hosted agent has not signtool.exe, so you should use private agent which has the signtool.exe on the machine.
Copy files task, Copy Files Over SSH task or Windows Machine File copy task: upload the file exe to your web server.