MsBuild doesnt start my project build. Why?

Posted on 2012-09-19
Last Modified: 2012-10-04
I have created a class libary called BuildToolUtility. I have then done a script with msbuild but it wont start and I dont understand why. I start it with:

msbuild Build.proj /t:AutoIncrement

Open in new window

I then get this error:

    Build started 2012-09-19 10:04:35.
    Project "C:\Build\BuildToolUtility\Build.proj" on node 1 (AutoIncre
    ment target(s)).
    C:\Build\BuildToolUtility\Build.proj : error MSB4057: The target "A
    utoIncrement" does not exist in the project.
    Done Building Project "C:\Build\BuildToolUtility\Build.proj" (AutoI
    ncrement target(s)) -- FAILED.

Open in new window

My Build.proj script

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" DefaultTargets="IncrementBuild"  xmlns="">
<UsingTask AssemblyFile="bin\debug\BuildToolUtility.dll" TaskName="AutoIncrementTask" />
<Target Name="IncrementBuild">                                   
<AutoIncrementTask AssemblyInfoPath="..\..\CommonAssemblyInfo.cs" />

Open in new window

And here is my AutoIncrementTask.cs


 using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Text;
            using System.Text.RegularExpressions;
            using Microsoft.Build.Utilities;
            using System.IO;
                namespace BuildToolUtility
                    public class AutoIncrementTask : Task
                    private const string VersionPattern = @"\[assembly: AssemblyFileVersion\(\""(\d{1}).(\d{1}).(\d{1,}).(\d{6})""\)\]";
                    public string AssemblyInfoPath { get; set; }
                    public void main ()
                        AutoIncrementTask t = new AutoIncrementTask();
                    public override bool Execute()
                            if (String.IsNullOrEmpty(AssemblyInfoPath))
                                throw new ArgumentException("AssemblyInfoPath must have a value");
                             string[] content = File.ReadAllLines(AssemblyInfoPath, Encoding.Default);
                            var rx = new Regex(VersionPattern);
                            var newContent = new List<string>();
                            content.ToList().ForEach(line =>
                                if (rx.IsMatch(line))
                                    line = VersionMatcher(rx.Match(line));
                            File.WriteAllLines(AssemblyInfoPath, newContent);
                         catch (Exception ex)
                            return false;
                        return true;
                    private string VersionMatcher(Match match)
                        int major = int.Parse(match.Groups[1].Value);
                        int minor = int.Parse(match.Groups[2].Value);
                        int build = int.Parse(match.Groups[3].Value);
                        string revision = match.Groups[4].Value;
                        Console.WriteLine("AutoIncrement Assembly {0}", Path.GetFileName(AssemblyInfoPath));
                        Console.WriteLine("Current matched version: {0}.{1}.{2}.{3}", major, minor, build, revision);
                        revision = String.Format("{0}{1:d2}{2:d2}",
                        Console.WriteLine("Incremented to version: {0}.{1}.{2}.{3}", major, minor, build, revision);
                         string result = match.Result("[assembly: AssemblyFileVersion(\"$1.$2.{0}.{1}\")]");
                        return String.Format(result, build, revision);

Open in new window

Question by:Mickeys
    LVL 43

    Expert Comment

    Surely the error message gives you a big hint:
    error MSB4057: The target "AutoIncrement" does not exist in the project.

    Looking at your supplied files the message is correct, there is no project with that name.  (There is one with a similar name)

    Author Comment

    but AutoIncrementTask gives the same error
    LVL 16

    Accepted Solution

    I have little experience messing with msbuild directly, but I believe the target must point to an actual "target" node in the project. Not a task and definitely not a .cs file.

    In your project file the target name is "IncrementBuild".

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now