Example #1
0
        public bool BuildProject()
        {
            Log = "";
            bool buildResultOK = false;

            BuildResultDll    = BuildResultSymbols = "";
            BuildResultAssets = null;
            try
            {
                using (bLogger BuildLogger = new bLogger())
                {
                    // usage Microsoft.Build.BuildEngine.Engine is prevelegy of MONO runtime
                    Microsoft.Build.BuildEngine.Engine eng = Microsoft.Build.BuildEngine.Engine.GlobalEngine;
                    eng.RegisterLogger(BuildLogger);
                    Microsoft.Build.BuildEngine.Project prj = new Microsoft.Build.BuildEngine.Project(eng);

                    prj.Load(ProjectLocation);

                    logger.Debug("building project: {0}", ProjectLocation);
                    // todo: add configuration set option

                    if (!string.IsNullOrWhiteSpace(this.Configuration))
                    {
                        eng.GlobalProperties.SetProperty("Configuration", this.Configuration);
                    }
                    string outd = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "_tempArtifacts");
                    eng.GlobalProperties.SetProperty("OutputPath", outd);
                    eng.GlobalProperties.SetProperty("Platform", "AnyCPU");

                    string fileLib = System.IO.Path.Combine(outd,
                                                            prj.GetEvaluatedProperty("TargetFileName"));
                    string fileSymbols = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileLib), System.IO.Path.GetFileNameWithoutExtension(fileLib) + ".mdb");

                    buildResultOK = prj.Build();
                    eng.UnregisterAllLoggers();

                    Log = BuildLogger.Result();
                    if (buildResultOK)
                    {
                        BuildResultDll     = fileLib;
                        BuildResultSymbols = fileSymbols;
                        List <string> files = new List <string>();
                        foreach (string F in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(fileLib)))
                        {// TODO: not recursive! not now...
                            if (F != BuildResultDll && F != BuildResultSymbols)
                            {
                                files.Add(F);
                            }
                        }
                        BuildResultAssets = files.ToArray();
                    }
                }
            }
            catch (Exception e)
            {
                Log += string.Format("major exception while build: {0}", e.Message);
            }
            return(buildResultOK);
        }
        public static Microsoft.Build.BuildEngine.Engine CreateMSEngine(NAnt.VSNet.Tasks.SolutionTask solutionTask)
        {
            if (_msbuild != null)
            {
                return(_msbuild);
            }

            // map current target framework to TargetDotNetFrameworkVersion
            TargetDotNetFrameworkVersion frameworkVersion = GetTargetDotNetFrameworkVersion(
                solutionTask.Project.TargetFramework);

            // use the framework directory as BinPath
            string frameworkDir = ToolLocationHelper.GetPathToDotNetFramework(
                frameworkVersion);

            _msbuild = new Microsoft.Build.BuildEngine.Engine(frameworkDir);
            _msbuild.UnregisterAllLoggers();

            _msbuild.RegisterLogger(
                new NAntLogger(solutionTask,
                               solutionTask.Verbose ? Microsoft.Build.Framework.LoggerVerbosity.Normal : Microsoft.Build.Framework.LoggerVerbosity.Minimal
                               )
                );

            /*
             * foreach (PropertyTask property in solutionTask.CustomProperties) {
             *  string val;
             *  // expand properties in context of current project for non-dynamic properties
             *  if (!property.Dynamic) {
             *      val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.Location);
             *  }
             *  else
             *      val = property.Value;
             *  _msbuild.GlobalProperties.SetProperty(property.PropertyName, val);
             * }
             */

            return(_msbuild);
        }
Example #3
0
        public static Microsoft.Build.BuildEngine.Engine CreateMSEngine(NAnt.VSNet.Tasks.SolutionTask solutionTask)
        {
            if (_msbuild!=null) {
                return _msbuild;
            }

            // map current target framework to TargetDotNetFrameworkVersion
            TargetDotNetFrameworkVersion frameworkVersion = GetTargetDotNetFrameworkVersion(
                solutionTask.Project.TargetFramework);

            // use the framework directory as BinPath
            string frameworkDir = ToolLocationHelper.GetPathToDotNetFramework(
                frameworkVersion);

            _msbuild = new Microsoft.Build.BuildEngine.Engine(frameworkDir);
            _msbuild.UnregisterAllLoggers();

            _msbuild.RegisterLogger(
                new NAntLogger(solutionTask,
                solutionTask.Verbose ? Microsoft.Build.Framework.LoggerVerbosity.Normal : Microsoft.Build.Framework.LoggerVerbosity.Minimal
                )
                );

            /*
            foreach (PropertyTask property in solutionTask.CustomProperties) {
                string val;
                // expand properties in context of current project for non-dynamic properties
                if (!property.Dynamic) {
                    val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.Location);
                }
                else
                    val = property.Value;
                _msbuild.GlobalProperties.SetProperty(property.PropertyName, val);
            }
            */

            return _msbuild;
        }