コード例 #1
0
 private static void DoGenerate(string projectname, string generator = "")
 {
     if (File.Exists(projectname) || Directory.Exists(projectname))
     {
         Console.Error.WriteLine($"{progname}: file or directory {projectname} already exists.");
     }
     else
     {
         VSGlobals.ProjectName = projectname;
         if (string.IsNullOrWhiteSpace(generator))
         {
             generator = progname;
         }
         GeneratorManager.Generate(generator);
     }
 }
コード例 #2
0
        static void Main(string[] args)
        {
            Settings.Go();
            VSGlobals.ProjectGUID = Guid.NewGuid();
            var s = VSGlobals.ExpandMacros("$$(PROJECTGUID)");

            var codeBase = System.Reflection.Assembly.GetEntryAssembly().CodeBase;

            progname = Path.GetFileNameWithoutExtension(codeBase);
            try
            {
                var arglist = args.ToList();

                if (args.Count() == 0)
                {
                    Console.WriteLine($"{progname} - make various types of Visual Studio solution and start Visual Studio.\n");
                    Console.WriteLine("Usage:\n\n    proggen <SOLUTIONTYPE> <solution-name> <solution-name> ...\n");
                    Console.WriteLine("An instance of Visual Studio is started for each solution name specified.");
                    Console.WriteLine("Solutions types are as follows:\n");
                    foreach (var helpText in GeneratorManager.HelpTexts)
                    {
                        Console.WriteLine(helpText);
                    }
                    Console.WriteLine("\nAlternatively if this program has the name of one of the solution types\nabove, the solution type parameter is not needed (the solution type is determined from the program name).");
                    Console.WriteLine($"\nSpecifying {progname} -makeg with no other parameters causes proggen to\ncopy itself to each of the solution-types specified above (with\na .exe extension)");
                    Environment.Exit(0);
                }
                else if (args[0] == "-makeg" || args[0] == "--makeg")
                {
                    if (args.Count() > 1)
                    {
                        throw new Exception("-makeg option does not take parameters");
                    }
                    GeneratorManager.MakeAllGenerators();
                    Environment.Exit(0);
                }
                else if (args[0] == "-instances")
                {
                    if (args.Count() > 1)
                    {
                        throw new Exception("-instances does not take parameters.");
                    }
                    var vs2017Info = new VS2017Info.Vs2017SetupConfig();
                    var instances  = vs2017Info.VSInstances;
                    foreach (var instance in instances)
                    {
                        Console.WriteLine($"ID: {instance.Id} Path: {Path.Combine(instance.InstalledPath, instance.ProductPath)}");
                    }
                    Environment.Exit(0);
                }
                else if (args[0] == "-version" || args[0] == "--version")
                {
                    PrintProgramVersion();
                    Environment.Exit(0);
                }

                var generatorName = "";
                // is the program name a generator name?
                if (GeneratorManager.IsAGenarator(progname))
                {
                    generatorName = progname;
                    if (arglist[0] == "-g")
                    {
                        if (arglist.Count < 2)
                        {
                            throw new Exception("You must specify the name of a project to create.");
                        }
                        Utility.Shift(ref arglist);
                    }
                }
                else
                {
                    bool haveOption = arglist[0][0] == '-';
                    var  minargs    = haveOption ? 3 : 2;
                    if (arglist.Count < minargs)
                    {
                        throw new Exception("You must specify at least one project name.");
                    }

                    if (haveOption)
                    {
                        var option = arglist[0];
                        if (option != "-g")
                        {
                            throw new Exception($"'{option}' is an invalid option");
                        }
                        Utility.Shift(ref arglist);
                    }

                    generatorName = arglist[0];
                    if (!GeneratorManager.IsAGenarator(generatorName))
                    {
                        throw new Exception($"'{generatorName}' is not a valid project type.");
                    }
                    Utility.Shift(ref arglist);

                    // alternatively an option can go after the project type:
                    var optionAfterGenerator = arglist[0][0] == '-';
                    if (optionAfterGenerator)
                    {
                        var option = arglist[0];
                        if (option != "-g")
                        {
                            throw new Exception($"'{option}' is an invalid option");
                        }
                        Utility.Shift(ref arglist);
                    }
                }

                foreach (var project in arglist)
                {
                    if (project[0] == '-')
                    {
                        Console.Error.WriteLine($"{progname}: option {project} ignored.");
                    }
                    else
                    {
                        DoGenerate(project, generatorName);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"{progname}: error: {ex}");
            }
        }