예제 #1
0
        public void BuildProject(ProjectDescriptor project)
        {
#pragma warning disable IDE0062 // Make local function 'static'
            void WriteProcessError(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrWhiteSpace(e.Data))
                {
                    UnityEngine.Debug.LogError(e.Data);
                }
            }

            void WriteProcessOutput(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrWhiteSpace(e.Data))
                {
                    UnityEngine.Debug.Log(e.Data);
                }
            }

#pragma warning restore IDE0062 // Make local function 'static'

            var csprojPath = NamesPaths.CreateCsprojPathFromAsmDefPath(project.AsmdefPath);

            if (!File.Exists(csprojPath))
            {
                UnityEngine.Debug.LogWarning($"Skipping project file, because it does not exists: {csprojPath}");
                return;
            }

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "dotnet",
                    Arguments              = $"build \"{csprojPath}\"",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            var outputHandler = new DataReceivedEventHandler(WriteProcessOutput);
            var errorHandler  = new DataReceivedEventHandler(WriteProcessError);

            UnityEngine.Debug.Log($"Starting {project.AsmdefPath} build");

            process.OutputDataReceived += outputHandler;
            process.ErrorDataReceived  += errorHandler;

            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();

            process.OutputDataReceived -= outputHandler;
            process.ErrorDataReceived  -= errorHandler;

            UnityEngine.Debug.Log($"Finished {project.AsmdefPath} build");
        }
예제 #2
0
        private static void CreateDefaultFiles(string baseDirectory, string asmdefPath, bool overwrite)
        {
            var nugetBase = Path.Combine(baseDirectory, NamesPaths.BaseFolder);

            FileHelper.EnsureFileCreated(NamesPaths.CreateCsprojPathFromAsmDefPath(asmdefPath), FileResources.DefaultCsproj, overwrite);
            FileHelper.EnsureFileCreated(Path.Combine(nugetBase, ".gitignore"), FileResources.ProjectGitIgnore, overwrite);
            FileHelper.EnsureFileCreated(Path.Combine(nugetBase, "Nuget", ".gitignore"), FileResources.DllGitIgnore, overwrite);
        }
예제 #3
0
        public string ProcessSolutionFile(string slnContent)
        {
            if (!_options.AddProjectsToSolution)
            {
                return(slnContent);
            }

            var projects = _projectDiscoverer.FindAsmdefPaths().ToArray();

            using (var reader = new StringReader(slnContent))
            {
                var sb = new StringBuilder();

                string line;
                var    projectGuids = new List <Guid>();
                while (!((line = reader.ReadLine()) is null))
                {
                    sb.AppendLine(line);

                    if (line.Contains("# Visual Studio 15"))
                    {
                        foreach (var project in projects)
                        {
                            var csprojPath = NamesPaths.CreateCsprojPathFromAsmDefPath(project.AsmdefPath);

                            if (!File.Exists(csprojPath) || csprojPath.EndsWith(".sln"))
                            {
                                continue;
                            }

                            var nugetProjectName = new FileInfo(csprojPath).Name.Replace(".asmdef", ".Nuget");

                            if (slnContent.Contains(nugetProjectName))
                            {
                                continue;
                            }

                            var projectGuid = Guid.NewGuid();

                            var lineToAdd = $"Project(\"{{9A19103F-16F7-4668-BE54-9A1E7A4F7556}}\") = \"{nugetProjectName}\", \"{csprojPath}\", \"{{{projectGuid}}}\"";

                            if (slnContent.Contains(lineToAdd))
                            {
                                continue;
                            }

                            sb.AppendLine(lineToAdd);
                            sb.AppendLine("EndProject");

                            projectGuids.Add(projectGuid);
                        }
                    }
                    else if (line.Contains("GlobalSection(ProjectConfigurationPlatforms) = postSolution"))
                    {
                        foreach (var addedGuid in projectGuids)
                        {
                            var firstLine = $"		{{{addedGuid}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU";

                            if (slnContent.Contains(firstLine))
                            {
                                continue;
                            }

                            sb.AppendLine(firstLine);
                            sb.AppendLine($"		{{{addedGuid}}}.Debug|Any CPU.Build.0 = Debug|Any CPU");
                            sb.AppendLine($"		{{{addedGuid}}}.Release|Any CPU.ActiveCfg = Release|Any CPU");
                            sb.AppendLine($"		{{{addedGuid}}}.Release|Any CPU.Build.0 = Release|Any CPU");
                        }
                    }
                }

                return(sb.ToString());
            }
        }