I am using VS 2015 and trying to execute a PowerShell after publishing the web application. I have created a publish profile, compiling in release mode and publish method is a file system, then in my project XML I have added a target
<Target Name="Mytarget2" AfterTargets="MSDeployPublish">
<Error Text="he name of the publish profile is $(DestinationAppRoot)">
</Error>
</Target>
so I am expecting an error message after publishing through visual studio but not getting anything and how can I call PowerShell script if I get it working?
VS 2015 MSDeployPublish not executing
That because you are publishing your project from File System. The target "MSDeployPublish" is not supported by the File System.
"We currently do not support executing custom targets after publish from VS for the file system protocol. If you publish from the command line the target will be executed however."
So, you could use MSBuild command line to execute this custom target by specify the target, /t:Mytarget2:
msbuild "YourSolutionFile" /t:Build,Mytarget2 /p:DeployOnBuild=true /p:PublishProfile=YourPublishFile.pubxml
Or you can change settings in VS to build with high verbosity and see whichis the last target to be executed, then you can use it instead of target MSDeployPublish, for example, PipelineTransformPhase, so the custom target looks like:
<Target Name="Mytarget2" AfterTargets="PipelineTransformPhase">
<Error Text="he name of the publish profile is $(DestinationAppRoot)">
</Error>
</Target>
Hope this helps.
Related
I am establishing a new Azure DevOps build server on an Azure VM running Windows Server 2022. Running the VsixSignTool fails in the build pipeline on this server.
I am replacing an old build server where this pipeline runs correctly. The old build server has Visual Studio 2019 and 2022 Community installed; the new build server only has the Visual Studio Build Tools.
Setup
Visual Studio Build Tools 2022 (17.4.1) and other dependencies like WIX toolset etc are all installed on the server. As part of the Visual Studio Build Tools, the following components are installed (exported from the Visual Studio Installer):
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.CoreBuildTools",
"Microsoft.VisualStudio.Workload.MSBuildTools",
"Microsoft.VisualStudio.Component.TestTools.BuildTools",
"Microsoft.Net.Component.4.8.SDK",
"Microsoft.Net.Component.4.7.2.TargetingPack",
"Microsoft.VisualStudio.Component.Windows11SDK.22621",
"Microsoft.VisualStudio.Component.NuGet.BuildTools",
"Microsoft.VisualStudio.Web.BuildTools.ComponentGroup",
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
"Microsoft.VisualStudio.Component.TypeScript.TSServer",
"Microsoft.Net.Component.4.8.TargetingPack",
"Microsoft.Net.ComponentGroup.4.8.DeveloperTools",
"Microsoft.NetCore.Component.Runtime.6.0",
"Microsoft.NetCore.Component.Runtime.7.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.DockerTools.BuildTools",
"Microsoft.Component.ClickOnce.MSBuild",
"Microsoft.VisualStudio.Wcf.BuildTools.ComponentGroup",
"Microsoft.VisualStudio.Component.WebDeploy",
"Microsoft.Net.Component.3.5.DeveloperTools",
"Microsoft.VisualStudio.Workload.WebBuildTools",
"Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools",
"Microsoft.Net.Component.4.6.TargetingPack",
"Microsoft.VisualStudio.Component.VSSDKBuildTools",
"Microsoft.VisualStudio.ComponentGroup.VisualStudioExtensionBuildTools.Prerequisites",
"Microsoft.VisualStudio.Workload.VisualStudioExtensionBuildTools",
"Microsoft.VisualStudio.Component.SQL.SSDTBuildSku",
"Microsoft.NetCore.Component.Runtime.5.0"
]
}
One of the projects in my solution is a VSIX package. The project has a PackageReference to the current version of the VsixSignTool:
<PackageReference Include="Microsoft.VSSDK.Vsixsigntool">
<Version>16.2.29116.78</Version>
</PackageReference>
and it has an afterbuild target to sign the VSIX package:
<PropertyGroup>
<VsixSignTool>$(NuGetPackageRoot)microsoft.vssdk.vsixsigntool\16.2.29116.78\tools\vssdk\vsixsigntool.exe</VsixSignTool>
<VsixSignCommand>$(VsixSignTool) sign /f $(SIGN_CERTIFICATE) /p $(SIGN_PASSWORD) /sha1 $(SIGN_CERT_HASH) /fd sha256 /t $(SIGN_TIMESTAMPSERVER)</VsixSignCommand>
</PropertyGroup>
<Target Name="AfterBuild" DependsOnTargets="CoreCompile" Condition="Exists('$(SIGN_CERTIFICATE)')">
<Message Text="Signing $(TargetVsixContainer)" />
<Exec Command="$(VsixSignCommand) $(MSBuildProjectDirectory)\$(TargetVsixContainer)" />
</Target>
Problem
When the pipeline runs, it fails when attempting to sign the package. This is the output (slightly obfuscated):
"C:\Users\(AzureDevOpsAgentUser)\.nuget\packages\microsoft.vssdk.vsixsigntool\16.2.29116.78\tools\vssdk\vsixsigntool.exe sign /f (path to pfx file) /p (the password) /sha1 (the certificate hash) /fd sha256 /t (timestamp server) (path to newly built vsix file)" exited with code -1073741515.
The Azure DevOps Agent user is local administrator on the build server.
Apart from the fact that it fails, this all looks good. When I connect to the build server, the vsixsigntool.exe is indeed in the expected location. All options to the vsixsigntool are correct. In fact, I temporarily installed the OpenVsixSignTool and could use this from powershell to sign the vsix with the exact same options. So, the certificate, password, hash etc are all correct and work. A side note: I would prefer to stick to the official vsixsigntool and avoid shifting to the OpenVsixSignTool.
Trying to run the vsixsigntool by hand from an elevated PowerShell does not do anything at all. It does not sign the vsix and it gives absolutely no output whatsoever. As a matter of fact, even if I give the vsixsigntool utter rubbish as options, it just completes with absolutely no information or errors. Here a copy/paste from PowerShell (elevated):
PS C:\Users\(Azure DevOps Agent User)\.nuget\packages\microsoft.vssdk.vsixsigntool\16.2.29116.78\tools\vssdk> .\vsixsigntool.exe /absolute /rubbish /for /you mate
PS C:\Users\(Azure DevOps Agent User)\.nuget\packages\microsoft.vssdk.vsixsigntool\16.2.29116.78\tools\vssdk>
It just silently runs with bad input and gives no information at all. Nothing in the event log. I am at a total loss.
What am I missing here? Any help greatly appreciated!
I'm using the build process template that comes with TFS 2013 (TfvcTemplate.12.xaml). I want to create a new build definition that runs a bunch of PowerShell scripts; however, I do not have anything .NET to build. TF build does not seem to like that. I'm getting this error below when leaving the solution/project files field blank. Is there any way to get around this?
TF215097: An error occurred while initializing a build for build definition \MyProjectRoot\MyBuildDefinition:
Exception Message:
The process parameter ProjectsToBuild is required but no value was set. A value must be set on the definition or when the build is queued (Category: #200 Build, Display Name: 1. Projects). (type ArgumentException)
Exception Stack Trace:
at Microsoft.TeamFoundation.Build.Hosting.BuildWorkflowInstance.ValidateParameters(BuildWorkflowDefinition definition, IDictionary`2 passedInParameterValues) at Microsoft.TeamFoundation.Build.Hosting.BuildWorkflowInstance.Initialize(BuildWorkflowDefinition definition, IDictionary`2 dataContext)
at Microsoft.TeamFoundation.Build.Hosting.BuildWorkflowManager.TryStartWorkflow(WorkflowRequest request, WorkflowManagerActivity activity, BuildWorkflowInstance& workflowInstance, Exception& error, Boolean& syncLockTaken)
In TFS 2015 (or Visual Studio Online) the new TFS Build system no longer has this limitation.
In TFS 2013 what I often do (to avoid having to muck around with the workflow), is just provide a dummy MSBuild .proj file that does nothing.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="Build">
<Target Name="Build">
<Message Text="This MSBuild is a placeholder and does nothing" />
</Target>
</Project>
An alternative to Dylan's solution, but something very similar that I do is to create an empty Solution file (.sln) in visual studio and mention that within the build definition/workflow.
You'll need to create your own Process Template (you can probably steal quite a bit from the standard template), and you'll need to rip out the Run MsBuild for Project activity as well as the parameters that are defined specifically for that activity (that will be quite a bit of the default template).
That should allow you to jump directly to the powershell sections.
I currently have a CI Setup in TFS 2013 which does the following
Pulls code down from Git on every commit to a branch
Builds the Solution
Runs N-Unit Tests Against the solution
Runs Jasmine Front-end Tests against the javascript
Deploys on success via WebDeploy to chosen server.
I have now managed to install Grunt and NodeJS on the server to do some manipulation of the Javascript between steps 5-6. Does anyone have any advice on how this might be done?
I've tried post-tests scripts to minify the javascript successfully on both the src and bin/_PublishedWebsites directory but this does not seem to persist over to the deployment server. And infact, the _PublishedWebsites route puts the build folder in an undeletable state due to maxmimum character limits on Windows files (argh).
You should switch over to using Release Management for Visual Studio 2013 (works with 2012 as well). This allows you to parameterize your release and push the same output through multiple environments. Very configurable and even makes sure that the tools you need end up on the server that you are deploying to. Supports Puppet, Chef, DSC, and create your own.
http://nakedalm.com/installing-release-management-server-tfs-2013/
And for an overview: http://nakedalm.com/building-release-pipeline-release-management-visual-studio-2013/
I managed to get this working with the addition of two extra steps to the pubxml file used for the deployment.
First, i added a dependency powershell script which ran NPM install and grunt tasks.
<PipelineDependsOn>
CustomBeforePublish;
$(PipelineDependsOn);
</PipelineDependsOn>
<Target Name="CustomBeforePublish">
<Exec Command="powershell.exe -ExecutionPolicy Unrestricted -file Pre_Deploy_Javascript_Build.ps1 $(ProjectDir)"/>
</Target>
Following this. I had now created additional files which did not exist in the project. I had to now ensure that these were published. To do this, i added another step.
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
CopyMinJSFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn >
<Target Name="CopyMinJSFiles">
<ItemGroup>
<_MinJSFiles Include="$(ProjectDir)\App\*.js" />
<FilesForPackagingFromProject Include="%(_MinJSFiles.Identity)">
<DestinationRelativePath>App\%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
Basically I'd like to use the NUnit plugin for TeamCity (the program, not necessarily the specific build step using it) to run my unit tests, with NCover for code coverage, and since my unit tests uses TypeMock 6, I need that too working.
So far I've tried:
Just basically pointing the TeamCity NUnit build-step to my dll's, but that fails with the following error message:
Typemock Isolator needs to be linked with Coverage Tool to run, to enable do one of the following:
link the Coverage tool through the Typemock Isolator Configuration
run tests via TMockRunner.exe -link
use TypeMockStart tasks for MSBuild or NAnt with Link
Trying to figure out the right command line, I tried this:
C:...\Isolator\6.0\TMockRunner.exe "C:\TeamCity...\JetBrains.BuildServer.NUnitLauncher.exe" v4.0 MSIL NUnit-2.5.9 MyAssembly.dll
This fails with the exact same error.
Setting the environment variables found in the mocking_on.bat file part of TypeMock, this doesn't change the outcome.
Note that the above examples doesn't contain any reference to NCover (yet), that's because I've been hacking around on the command line for a couple of hours with the above examples and still haven't gotten basic unit-tests running. NCover is extra options to the nunit-launcher of TeamCity so I hope this is as simple as just enabling that when I get that far.
Since TypeMock requires you to use their own runner program, TMockRunner, there's no way to just use the GUI options in TeamCity to get everything set up.
Instead, what I ended up doing was to first build a custom msbuild file with this contents:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TypeMockLocation>C:\Program Files (x86)\TypeMock\Isolator\6.0</TypeMockLocation>
<NUnit>"C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.NUnitLauncher.exe"</NUnit>
<NCover>C:\Program Files (x86)\NCover\NCover.Console.exe</NCover>
</PropertyGroup>
<Import Project="$(TypeMockLocation)\TypeMock.MSBuild.Tasks"/>
<Target Name="TestWithTypeMock">
<TypeMockStart Link="NCover3.0" ProfilerLaunchedFirst="true" Target="2.0"/>
<Exec ContinueOnError="true" Command="$(NUnit) v2.0 x86 NUnit-2.5.9 SqlDatabases.Core.Tests\bin\Debug\SqlDatabases.Core.Tests.dll SqlDatabases.SqlServer.Tests\bin\Debug\SqlDatabases.SqlServer.Tests.dll /ncover:%22$(NCover)%22 /ncover-arg://ias /ncover-arg:SqlDatabases.Core /ncover-arg://ias /ncover-arg:SqlDatabases.SqlServer /ncover-arg://et /ncover-arg:.*Exception /ncover-arg://x /ncover-arg:c:\temp\coverage.xml"/>
<TypeMockStop/>
</Target>
</Project>
This file I save to a directory on my TeamCity server. Since I didn't want the test script to be part of my repository, I didn't add it to source control (I can build and right-click and run tests from within Visual Studio, if I get something not so tied to my build server I might change that decision later). Also, I only have 1 build-agent for my TeamCity server so this works for me for the time being.
In addition to the above file, I added the following batch-file:
#echo off
setlocal
set CURDIR=%CD%
copy c:\dev\sqldatabases\tests.msbuild .\
msbuild tests.msbuild /target:TestWithTypeMock
rd /s /q c:\dev\sqldatabases\codecoverage
md c:\dev\sqldatabases\codecoverage
"c:\program files\ncover\ncover.reporting.exe" c:\temp\coverage.xml //or FullCoverageReport:Html:c:\dev\sqldatabases\codecoverage
cd \dev\sqldatabases\codecoverage
del %CURDIR%\coverage.zip
7z a -r %CURDIR%\coverage.zip
And then I added the following two build-steps to my TeamCity build configuration:
Visual Studio Solution: Build the debug configuration.
Execute C:\Dev\SqlDatabases\Tests.bat (the above batch file)
I made sure that coverage.zip was listed under artifacts in my build configuration, and now I got code coverage, typemock, and unit tests.
Only thing I haven't figured out how to get so far is that if I click on the build result of a build configuration that uses the normal TeamCity GUI for setting up everything (minus TypeMock), I get a code coverage short summary listed, this is not present in the above setup, but the full report is, and the tab in the TeamCity build results.
Hopefully this can save someone else some trouble.
Lasse,
So long as you're using the TeamCity GUI, running with NCover coverage should just be a simple matter of selecting to run with it.I've never tried throwing Typemock into the mix, so I look forward to hearing how that goes.
In my org, we are planning to go for nant for .net web applications. Source control is TFS, visual studio 2008. I would like to know how to do Builds with Nant? How to create msi and deploy the application using Nant? Is separate Build machine is required to do builds with nant? Somebody please help me out. I need step wise process. Thanks in advance.
Thanks
Shanthi
For a step-by step guide to using NAnt I suggest referring to the NAnt project documentation for the fundamental concepts. Once you are familiar with it's basic usage I suggest investigating the nant-contrib project to obtain more build tasks.
One part of your question that I would like to address directly here is the question of whether a separate machine is required to use NAnt. NAnt does not strictly require a separate machine, however a separate machine might be beneficial if your build process is automated or particularly intensive
[Update]
In response to comment from OP:
NAnt views the build process as a series of individual tasks to be performed as part of a target. The normal process for building an application would be to invoke a compiler on the source files in order to produce a binary, NAnt has a number of tasks that invoke language compilers
In this example I will invoke the C# language compiler (csc.exe) using the task in an NAnt build file for a Hello World application that consists of a single source file named hello.cs.
<?xml version="1.0"?>
<project name="Hello World" default="build" basedir=".">
<property name="debug" value="true" overwrite="false" />
</target>
<target name="build" description="compiles the source code">
<csc target="exe" output="HelloWorld.exe" debug="${debug}">
<sources>
<includes name="HelloWorld.cs" />
</sources>
</csc>
</target>
</project>
Let's examine this XML:
<project name="Hello World" default="build" basedir=".">
Things to Note:
The value of the default property is "build". This means that the target named "build" will be invoked if no other target is specified.
This is the build target, as the description states it will compile the source code. To do this the csc task is used. The csc task has a number of options including
target: This specifies the type of binary the target will produce. In this case an executable will be produced
output: specifies the name of the executable file that will be created
debug: The value of this property used a conditional property debug (defined above as false) which will determine whether the compiler produces an executable that contains debugging information
sources & include:
specifies the source files that the compiler will parse in order to produce the executable
As you can see the actions necessary to build the source code are defined in a target. A build file can define many targets which each call many tasks. To produce an MSI file you would inoke a task that produces an MSI file, unfortunately as I don't actually use NAnt regularly, you will have to do some research to find one although I have a feeling the nant-contrib project includes one given how common it is to produce an MSI.
I hope this explanation as clarified things for you
The information in this update has been distilled from this document in the NAnt documentation
Seperate build machine is not necessarily required, but it's definetely recommended.
You'll want to look into using the following tools:
CruiseControl .NET
TFS Plugin for CC.NET