[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 558
  • Last Modified:

MsBuild doesnt start my project build. Why?

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="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="bin\debug\BuildToolUtility.dll" TaskName="AutoIncrementTask" />
<Target Name="IncrementBuild">                                   
<AutoIncrementTask AssemblyInfoPath="..\..\CommonAssemblyInfo.cs" />
</Target>
</Project> 

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();
                        t.Execute();
                    }
        
                    public override bool Execute()
                    {
                        try
                        {
                            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));
                                newContent.Add(line);
                            });
        
                            File.WriteAllLines(AssemblyInfoPath, newContent);
        
                         }
                         catch (Exception ex)
                        {
                            Console.Out.WriteLine(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);
        
                        ++build;
                        revision = String.Format("{0}{1:d2}{2:d2}",
                            DateTime.Now.Year.ToString().Substring(2),
                            DateTime.Today.Month,
                            DateTime.Today.Day);
                        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

0
Mickeys
Asked:
Mickeys
1 Solution
 
AndyAinscowCommented:
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)
0
 
MickeysAuthor Commented:
but AutoIncrementTask gives the same error
0
 
ToddBeaulieuCommented:
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".
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now