コード例 #1
0
ファイル: ProjectManager.cs プロジェクト: ymotton/KRuntime
        public bool Clean(string defaultTargetFramework = "net45")
        {
            defaultTargetFramework = Environment.GetEnvironmentVariable("TARGET_FRAMEWORK") ?? defaultTargetFramework;

            KProject project;

            if (!KProject.TryGetProject(_projectDir, out project))
            {
                Trace.TraceInformation("Unable to locate {0}.'", KProject.ProjectFileName);
                return(false);
            }

            string outputPath = Path.Combine(_projectDir, "bin");
            string nupkg      = GetPackagePath(project, outputPath);

            var configurations = new HashSet <FrameworkName>(
                project.GetTargetFrameworkConfigurations()
                .Select(c => c.FrameworkName));

            if (configurations.Count == 0)
            {
                configurations.Add(VersionUtility.ParseFrameworkName(defaultTargetFramework));
            }

            bool success = true;

            foreach (var targetFramework in configurations)
            {
                try
                {
                    var result = Clean(project, outputPath, targetFramework);

                    if (result != null && result.Errors != null)
                    {
                        success = false;

                        Trace.TraceError(String.Join(Environment.NewLine, result.Errors));
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    Trace.TraceError(ex.ToString());
                }
            }

            if (File.Exists(nupkg))
            {
                Trace.TraceInformation("Cleaning {0}", nupkg);
                File.Delete(nupkg);
            }

            var di = new DirectoryInfo(outputPath);

            DeleteEmptyFolders(di);

            return(success);
        }
コード例 #2
0
ファイル: ProjectManager.cs プロジェクト: ymotton/KRuntime
        public bool Build(string defaultTargetFramework = "net45")
        {
            defaultTargetFramework = Environment.GetEnvironmentVariable("TARGET_FRAMEWORK") ?? defaultTargetFramework;

            KProject project;

            if (!KProject.TryGetProject(_projectDir, out project))
            {
                Trace.TraceInformation("Unable to locate {0}.'", KProject.ProjectFileName);
                return(false);
            }

            var sw = Stopwatch.StartNew();

            string outputPath = Path.Combine(_projectDir, "bin");
            string nupkg      = GetPackagePath(project, outputPath);

            var configurations = new HashSet <FrameworkName>(
                project.GetTargetFrameworkConfigurations()
                .Select(c => c.FrameworkName));

            if (configurations.Count == 0)
            {
                configurations.Add(VersionUtility.ParseFrameworkName(defaultTargetFramework));
            }

            var builder = new PackageBuilder();

            // TODO: Support nuspecs in the project folder
            builder.Authors.AddRange(project.Authors);

            if (builder.Authors.Count == 0)
            {
                // Temporary
                builder.Authors.Add("K");
            }

            builder.Description = project.Description ?? project.Name;
            builder.Id          = project.Name;
            builder.Version     = project.Version;
            builder.Title       = project.Name;

            bool success       = true;
            bool createPackage = false;

            // Build all target frameworks a project supports
            foreach (var targetFramework in configurations)
            {
                try
                {
                    var result = Build(project, outputPath, targetFramework, builder);

                    if (result != null && result.Errors != null)
                    {
                        success = false;
                        Trace.TraceError(String.Join(Environment.NewLine, result.Errors));
                    }
                    else
                    {
                        createPackage = true;
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    Trace.TraceError(ex.ToString());
                }
            }

            if (createPackage)
            {
                using (var fs = File.Create(nupkg))
                {
                    builder.Save(fs);
                }

                Trace.TraceInformation("{0} -> {1}", project.Name, nupkg);
            }

            sw.Stop();

            Trace.TraceInformation("Compile took {0}ms", sw.ElapsedMilliseconds);
            return(success);
        }