예제 #1
0
        private static CmdArgumentParseResponse ParseOptions(string[] arguments)
        {
            var parser = new Parser((settings) =>
            {
                settings.CaseSensitive          = false;
                settings.HelpWriter             = Console.Error;
                settings.IgnoreUnknownArguments = true;
            });

            var result = new CmdArgumentParseResponse
            {
                Result = CompletionResult.Failure
            };

            if (arguments == null || parser == null || result.Options == null)
            {
                result.Messages.Add("Invalid parse request");
                return(result);
            }

            //TDC: I had to switch to a local variable for the options, as it would not parse properly otherwise. Not entirely sure why.
            var options = new CmdLineOptions();

            if (!parser.ParseArguments(arguments, options))
            {
                result.Messages.Add(HelpText.AutoBuild(result).ToString());
                return(result);
            }

            result.Options = options;
            result.Result  = CompletionResult.Success;

            return(result);
        }
예제 #2
0
        private static BuildSolutionResponse BuildSolutions(CmdLineOptions options, ProjectCollection projectCollection)
        {
            var result = new BuildSolutionResponse();

            if (options == null || projectCollection == null)
            {
                result.Messages.Add("Invalid request");
                result.Result = CompletionResult.Failure;
            }

            var properties = new Dictionary <string, string>
            {
                { "Configuration", options.BuildConfiguration },
                { "Platform", options.BuildPlatform },
                { "RunSqlCodeAnalysis", "false" } //skip code analysis for this build as we will run it below
            };

            //the VisualStudioVersion is needed from the command line, else msbuild will throw errors
            AddConfigValue(properties, "VisualStudioVersion", ispath: false);
            AddConfigValue(properties, "SQLDBExtensionsRefPath");
            AddConfigValue(properties, "SqlServerRedistPath");
            AddConfigValue(properties, "MSBuildExtensionsPath");


            //SQL71558: The object reference [...].[...] differs only by case from the object definition [...].[...].
            properties.Add("SuppressTSqlWarnings", "71558"); //comma delimited

            var bp      = new BuildParameters(projectCollection);
            var loggers = new List <ILogger> {
                new ConsoleLogger()
            };

            bp.Loggers = loggers;

            var buildRequest = new BuildRequestData(options.SolutionPath, properties, options.ToolsVersion, new string[] { /* "Clean", */ "Build" }, null);
            var buildResult  = BuildManager.DefaultBuildManager.Build(bp, buildRequest);

            return(new BuildSolutionResponse
            {
                Result = buildResult.OverallResult == BuildResultCode.Success ? CompletionResult.Success : CompletionResult.Failure
            });
        }
예제 #3
0
        private static LoadProjectsResponse LoadProjects(CmdLineOptions options)
        {
            var result = new LoadProjectsResponse
            {
                Result = CompletionResult.Success
            };

            try
            {
                var solution = SolutionFile.Parse(options.SolutionPath);
                var pc       = new ProjectCollection();
                pc.SetGlobalProperty("Configuration", options.BuildConfiguration);

                Notify("Loading projects");

                var properties = new Dictionary <string, string>
                {
                    { "Configuration", options.BuildConfiguration },
                    { "Platform", options.BuildPlatform }
                };
                //the version is needed from the command line, else msbuild will throw errors
                AddConfigValue(properties, "VisualStudioVersion", ispath: false);
                AddConfigValue(properties, "SQLDBExtensionsRefPath");
                AddConfigValue(properties, "SqlServerRedistPath");
                AddConfigValue(properties, "MSBuildExtensionsPath");

                foreach (var p in solution.ProjectsInOrder.Where(s => s.RelativePath.EndsWith(".sqlproj")))
                {
                    var proj = pc.LoadProject(p.AbsolutePath, properties, options.ToolsVersion);
                    result.Projects.Add(proj);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                result.Messages.Add(e.Message);
                result.Result = CompletionResult.Failure;
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(result);
        }