Unable to find MSDeploy task within MSBuild - msbuild

I am trying to use the MSDeploy task within MSBuild (instead of calling it form the command line). I assumed this task was built in to MSBuild but I seem to be having trouble finding the task. The error Im getting is below. I have just re-installed the Web Deploy Tool to see if it might help.
C:\CLIENTS\DAM\Components\Umbraco\SiteTemplate_v6_1_6\Build>msbuild MSBuildScript.csproj -t:Deploy_v2
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18052]
<!-- some other stuff -->
error MSB4036: The "MSDeploy" task was not found. Check
the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and imple
ments the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks
files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

v10.0 can vary (v11.0 for example)
Do a search for your "Microsoft.WebApplication.targets" file and alter the import statement to match.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- Bunch of Other Stuff -->
<Target Name="AllTargetsWrapped">
<CallTarget Targets="ShowVariables" />
</Target>
<Target Name="ShowVariables" >
<Message Text="MSBuildExtensionsPath = $(MSBuildExtensionsPath)" />
</Target>

Related

Inexplicably cleared msbuild properties in TeamCity build

I'm trying to create a "tools NuGet package" that provides a tool and setting that is unpacked during build and used by a later TeamCity build step.
The NuGet package contains the following content in its build\MyPackageId.props file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MyTool1>$(MSBuildThisFileDirectory)..\tools\MyTool.exe</MyTool1>
</PropertyGroup>
<Target Name="ReportMyToolToTeamCity" BeforeTargets="PrepareToRun">
<PropertyGroup>
<MyTool2>$(MSBuildThisFileDirectory)..\tools\MyTool.exe</MyTool2>
</PropertyGroup>
<Message Text="MyTool1 = $(MyTool1)" />
<Message Text="MyTool2 = $(MyTool2)" />
</Target>
</Project>
(The messages will eventually set a TeamCity property, but this is sufficient to demonstrate the issue.)
Because it's a props file, after installing the NuGet package into a C# project it has added an import as the very first thing, above the import of Microsoft.Common.props. I want a props file rather than a targets file so that the property values are also available to other project settings and targets files.
When I compile this inside Visual Studio 2015, I see both MyTool1 and MyTool2 paths set to the same (correct) path as expected.
When I compile this from TeamCity (2017.2.2, using the Visual Studio (sln) runner), according to the output the MyTool1 property is empty and only MyTool2 shows the correct value.
Why?

MC.exe in msbuild

How do I compile with mc.exe in the correct way. Currently I have a build step which runs the relevant command but looking at developer network
There seems to be a better way.
I am not a expert with msbuild so please excuse how easy this question is. Googling has revealed no help
<Project
DefaultTargets="Build"
ToolsVersion="14.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Message Source Files">
<Extensions>mc;</Extensions>
<UniqueIdentifier>{B796B525-44D3-4260-8C76-705DBADA1043}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<MessageCompile Include="a.mc">
<GenerateBaselineResource>true</GenerateBaselineResource>
</MessageCompile>
</ItemGroup>
<Target Name="Build">
<DontKnowWhatGoesHere Sources="#(MessageCompile)"/>
</Target>
</Project>
MSBuild build are usually extended via .targets files, that have to be included in the project, and they extend the existing build proces. The WDK tasks for MSBuild page confirms this:
These command-line tools need to be exposed to MSBuild as tasks (contained in targets) so that they can be run during the build process.
The WDK MSDN page also has a help page on Windows driver targets:
The WindowsDriver.Common.targets, WindowsDriver.masm.targets, and WindowsDriver.arm.targets files provide the targets that are necessary to build a driver.
A quick grep in my C:\Program Files (x86)\Windows Kits\10\build directory showed that the MessageCompile target (the step that actually processes the MessageCompile items) is defined in the build\WindowsDriver.Common.targets file.
After importing the targets in your project you can do one of the following:
<Import
Project="C:\Program Files (x86)\Windows Kits\10\build\build\WindowsDriver.Common.targets" />
<!-- Option A: -->
<Target Name="Build" DependsOnTargets="MessageCompile">
<!-- no need to do anything, the dependency target should do the work -->
</Target>
<!-- Option B: -->
<Target Name="Build" DependsOnTargets="MessageCompile">
<!-- Use the Mc task which is the actual wrapper around the .exe,
see the .common.targets file for the list of all parameters -->
<Mc
Sources ="#(MessageCompile)"
ToolExe ="$(MessageCompileToolExe)"
ToolPath ="$(MessageCompileToolPath)"
Generated
/>
</Target>

Does CRuise Control use nAnt or MSbuild?

I am having issues understanding Cruise Control.
I would like to create a build automation in order to perform the build in my project. To do that I created the following entry in the ccnet.config file
<project name="My Web Release " description="Web config">
<workingDirectory>d:\GIT</workingDirectory>
<triggers/>
<sourcecontrol type="git">
<repository>GIT REPO</repository>
<branch>release-name</branch>
<autoGetSource>true</autoGetSource>
<fetchSubmodules>true</fetchSubmodules>
<executable>C:\Program Files (x86)\Git\cmd\git.exe</executable>
<tagOnSuccess>false</tagOnSuccess>
<commitBuildModifications>false</commitBuildModifications>
<commitUntrackedFiles>false</commitUntrackedFiles>
<tagCommitMessage> Build {0}</tagCommitMessage>
<tagNameFormat>Build-{0}</tagNameFormat>
<committerName>Build</committerName>
<committerEMail>build#build.com</committerEMail>
<workingDirectory>$(workingDirectory)\Sources\WEB</workingDirectory>
<timeout>600000</timeout>
</sourcecontrol>
<tasks>
<msbuild>
<executable>c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<buildFile>BuildScript.xml</buildFile>
<targets>NewBuild</targets>
<logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
<publishers>
<xmllogger />
<artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="50" />
</publishers>
</project>
And I do have a BuildScript.xml file.
My question is:
Is this a nAnt or MSBUILD script?
I am asking because I am trying to follow the documentation but I get a lot of issues regarding unknown tasks and so on.
For instance, this:
<property name="configuration" value="CLOSED" />
Would generate a unknown "property" task.
I am looking at MSBuild documentation to use a Move task.
and I got to this line:
<move file="originPath" tofile="TargetPath"/>
But I get:
BuildScript.xml(18,3): error MSB4036: The "Move" task was not
found. C heck the following: 1.) The name of the task in the project
file is the same as the name of the task class. 2.) The task class is
"public" and implements the Microsoft.Build.Framework.ITask interface.
3.) The task is correctly declared w ith in the project file, or in the *.tasks files located in the "C:
\Windows\Microsoft.NET\Framework\v2.0.50727" directory.
What is driving me crazy is that it was working before we migrated to Cruise Control.
Is this being interpreted as nAnt or MSBuild? Any ideas on why I am getting these errors?
It looks like your mixing nant and msbuild, if it was msbuild it would look like
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Tools="4.0">
<Target Name="Move">
<PropertyGroup>
<configuration>CLOSED</configuration>
</PropertyGroup>
<Move SourceFiles="Somefilefile" DestinationFolder="c:\temp"/>
</Target>
</Project>
So casing was an issue and that you need to specify the tools version as move is available from 4.0.

Inherit Parent MsBuild file

I have a project structure that looks like this:
Parent
-- ChildProjects1
-- ChildProjects2
-- ChildProjects3
I have an msbuild file under each ChildProjects node that builds the relevant projects, creates zip files, tags them in subversion etc
However most of this logic is common between ChildProjects. I'm wondering if I can refactor this common logic to sit in another msbuild file at the parent level and have each child inherit this?
Any ideas on this appreciated.
You can put common Targets inside an a file that you include using the following syntax, you will also see it in your proj files:
<Import Project="path to file.targets"/>
Things to note:
The convention is to use a .targets extension but it doesn't matter.
Where you place the import is important depending on if you want to be able to override properties or targets in the imported targets file.
Targets are not like methods, you cannot call them more than once but you can influence the order in which they are called.
If you require reusable chunks that you want to call multiple times create a custom task library but check out the MSBuildExtensionPack first to see if it has what you want.
Call Target
In relation to the question about CallTarget. CallTarget will invoke the specified target(s) the same way that DependsOnTargets, BeforeTargets and AfterTargets do. The target will only be run if it has not already been run. See the following example:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Foo">
<Target Name="Foo" DependsOnTargets="Bar">
<Message Text="Foo" />
<CallTarget Targets="Bar" />
<CallTarget Targets="Bar" />
</Target>
<Target Name="Bar" AfterTargets="Foo" BeforeTargets="Foo">
<Message Text="Bar" />
</Target>
</Project>
Which will output the following:
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18449]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 24/02/2014 12:06:59.
Project "D:\Dev\Test.proj" on node 1 (default targets).
Bar:
Bar
Foo:
Foo
Done Building Project "D:\Dev\Test.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.69

Unable to publish using msbuild or aspnet_compiler using cc.net

I am trying to automate publishing a project having many solutions in cc.net. I am using msbuild which in turn calls a aspnetcompiler xml file. Problem is my directory contains many solutions and when I run aspnetcompiler it gives me the following error.
errorASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
I have tried all possible solutions given at many forums. But I am confused how to explicitly tell aspnet_compiler to execute a particular project out of 20 projects.
I am using the ccnet build to call aspnet complier
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<!--msbuild exe directory -->
<workingDirectory>C:\cc\test\code\</workingDirectory>
<!--your working directory -->
<projectFile>C:\Program Files\CruiseControl.NET\server\AspNetCompilerConfiguration.xml</projectFile>
<!--the configuration xml file which will hold AspNetCompiler lines-->
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
this is my AspNetCompilerConfiguration.xml file
<Project
xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"
name = "AspNetPreCompile"
DefaultTargets = "PrecompileWeb">
<Target Name = "PrecompileWeb">
<AspNetCompiler
VirtualPath = "test"
PhysicalPath = "C:\cc\test\code\"
TargetPath = "C:\cc\testitr\deploy\"
Force = "true"
Debug = "true"
Updateable = "true"/>
</Target>
</Project>
Now I want to run C:\cc\test\code\Com.Project1.sln. but i dont know how to tell aspnet compiler. Any idea how to do this and then publish this.
First of all: you can't publish website by scirpt with aspnet_compiler but you can (Release-mode-)compile website which is generally the same thing. Or you can use MsBuild by the way I describe in this post.
I recommend you to group your ASP.NET Websites to solution files and build them. Then you have less params and you can test the build with Visual Studio.
Here is how you can use some params in your cc.net build file for msbuild-scirpt:
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<!--msbuild exe directory -->
<workingDirectory>C:\cc\test\code\</workingDirectory>
<!--your working directory -->
<projectFile>C:\Program Files\CruiseControl.NET\server\AspNetCompilerConfiguration.xml</projectFile>
<!--the configuration xml file which will hold AspNetCompiler lines-->
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
<!--Build arguments. You can have multiple projects or msbuild sections in cc.net.config-->
<buildArgs>/p:Configuration=Debug;MyAttribute1=MyValue1;MyAttribute2=MyValue2;</buildArgs>
<!--targets, if not default (here PrecompileWeb) -->
<targets>Build;Analyze</targets>
</msbuild>
Then you can modify your AspNetCompilerConfiguration.xml (better name in my opinion would be something like MyWebSites.msbuild) to take params:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" name = "AspNetPreCompile" DefaultTargets = "PrecompileWeb">
<!--Conditions are params from ccnet.config (or command line)-->
<PropertyGroup Condition="'$(MyAttribute1)' == MyValue1" >
<MySolution>c:\mything.sln</MySolution>
</PropertyGroup>
<PropertyGroup Condition="'$(MyAttribute1)' != MyValue1" >
<MySolution>c:\some_other.sln</MySolution>
</PropertyGroup>
<!--This way you could import other msbuild-scirpts to manage separate files-->
<!--<Import Project="Morexml.msbuild"/>-->
<Target Name="Build">
<Exec Command="echo hello world 1!"/>
<MSBuild Projects="$(MySolution)" Targets="Rebuild" ContinueOnError="false" StopOnFirstFailure="false" />
</Target>
<Target Name="Analyze">
<Exec Command="echo hello world 2!"/>
</Target>
<!--default, for example, here call some tasks -->
<!--default is not used when targets are specified -->
<Target Name="PrecompileWeb">
<CallTarget Targets="Build" />
<CallTarget Targets="Analyze" Condition="'$(MyAttribute2)' != 'MyValue2'" />
</Target>
</Project>
You can configure your solution .sln-file with Visual Studio or Notepad. However it should have your websites, something like this:
Project("{ABCD1234-7377-472B-9ABA-BC803B73C123}") = "MyWebSite", "http://localhost/MyWebSite", "{12345678-5FD6-4177-B210-54045B098ABC}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.VirtualPath = "/MyWebSite"
Debug.AspNetCompiler.PhysicalPath = "..\..\MyWebSite\"
Debug.AspNetCompiler.TargetPath = "C:\MyPublishedWebsite\"
Debug.AspNetCompiler.Updateable = "false"
Debug.AspNetCompiler.ForceOverwrite = "true"
...
There you can see the properties. There is no need for IIS any configuration. (Just check your released Web.Config (Release/Debug, etc. settings) or maybe use some msbuild-Target to handle that.)
Hope this helps!