Exemple #1
0
        private static void RunOptionsAndReturnExitCode(Options options)
        {
#if DEBUG
            Debugger.Launch();
            Console.WriteLine(Environment.CommandLine);
#endif
            var logger = new Logger();

            try
            {
                logger.Message("开始打源码包");

                var projectFile           = options.ProjectFile;
                var intermediateDirectory = options.IntermediateDirectory;
                var packageOutputPath     = options.PackageOutputPath;
                var packageVersion        = options.PackageVersion;

                logger.Message($@"项目文件 {projectFile}
临时文件{intermediateDirectory}
输出文件{packageOutputPath}
版本{packageVersion}
编译的文件{options.CompileFile}
资源文件{options.ResourceFile}
内容{options.ContentFile}
页面{options.Page}");

                var description = ReadFile(options.DescriptionFile);
                var copyright   = ReadFile(options.CopyrightFile);



                var buildProps = new BuildProps()
                {
                    Authors     = options.Authors,
                    Company     = options.Company,
                    Owner       = options.Owner ?? options.Authors,
                    Copyright   = copyright,
                    Description = description,
                    //PackageProjectUrl = options.PackageProjectUrl,
                    //RepositoryType = options.RepositoryType,
                    //RepositoryUrl = options.RepositoryUrl,
                    Title               = options.Title,
                    PackageIconUrl      = options.PackageIconUrl,
                    PackageLicenseUrl   = options.PackageLicenseUrl,
                    PackageReleaseNotes = options.PackageReleaseNotesFile,
                    PackageTags         = options.PackageTags
                };

                buildProps.SetSourcePackingDirectory(Path.GetFullPath(options.SourcePackingDirectory));

                new Packer(projectFile: projectFile,
                           intermediateDirectory: intermediateDirectory,
                           packageOutputPath: packageOutputPath,
                           packageVersion: packageVersion,
                           compileFile: options.CompileFile,
                           resourceFile: options.ResourceFile,
                           contentFile: options.ContentFile,
                           page: options.Page,
                           applicationDefinition: options.ApplicationDefinition,
                           noneFile: options.None,
                           embeddedResource: options.EmbeddedResource,
                           packageId: options.PackageId,
                           buildProps: buildProps,
                           packageReferenceVersion: options.PackageReferenceVersion).Pack();
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }

            string ReadFile(string file)
            {
                if (string.IsNullOrEmpty(file))
                {
                    return("");
                }

                file = Path.GetFullPath(file);
                if (File.Exists(file))
                {
                    try
                    {
                        return(File.ReadAllText(file));
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message);
                    }
                }

                return("");
            }
        }
Exemple #2
0
        private static void RunOptionsAndReturnExitCode(Options options)
        {
#if DEBUG
            Debugger.Launch();
            Console.WriteLine(Environment.CommandLine);
#endif
            var logger = new Logger();

            FixOptions(options);

            try
            {
                logger.Message("Source packaging");

                var projectFile = options.ProjectFile;
                var multiTargetingPackageInfo = new MultiTargetingPackageInfo(options);
                var intermediateDirectory     = GetIntermediateDirectory(multiTargetingPackageInfo, options, logger);
                // 当前多个不同的框架引用不同的文件还不能支持,因此随意获取一个打包文件夹即可
                // 为什么?逻辑上不好解决,其次,安装的项目的兼容性无法处理
                // 安装的项目的兼容性无法处理?源代码包有 net45 框架,项目是 net47 框架,如何让项目能兼容使用到 net45 框架?当前没有此生成逻辑
                var sourcePackingFolder = GetCommonSourcePackingFolder(multiTargetingPackageInfo, logger);
                var packageOutputPath   = options.PackageOutputPath;
                var packageVersion      = options.PackageVersion;

                //                logger.Message($@"项目文件 {projectFile}
                //临时文件{intermediateDirectory}
                //输出文件{packageOutputPath}
                //版本{packageVersion}
                //编译的文件{options.CompileFile}
                //资源文件{options.ResourceFile}
                //内容{options.ContentFile}
                //页面{options.Page}
                //SourcePackingDirectory: {options.SourcePackingDirectory}");

                var description = ReadFile(options.DescriptionFile);
                var copyright   = ReadFile(options.CopyrightFile);

                var buildProps = new BuildProps(logger)
                {
                    Authors     = options.Authors ?? string.Empty,
                    Company     = options.Company ?? string.Empty,
                    Owner       = options.Owner ?? options.Authors ?? string.Empty,
                    Copyright   = copyright,
                    Description = description,
                    //PackageProjectUrl = options.PackageProjectUrl,
                    //RepositoryType = options.RepositoryType,
                    //RepositoryUrl = options.RepositoryUrl,
                    Title               = options.Title,
                    PackageIconUrl      = options.PackageIconUrl,
                    PackageLicenseUrl   = options.PackageLicenseUrl,
                    PackageReleaseNotes = options.PackageReleaseNotesFile,
                    PackageTags         = options.PackageTags
                };

                buildProps.SetSourcePackingDirectory(sourcePackingFolder.FullName);

                var packer = new Packer
                             (
                    projectFile: projectFile,
                    intermediateDirectory: intermediateDirectory,
                    packageOutputPath: packageOutputPath,
                    packageVersion: packageVersion,
                    // 不再从 options 读取,多个框架的情况下,需要各自获取
                    //compileFile: options.CompileFile,
                    //resourceFile: options.ResourceFile,
                    //contentFile: options.ContentFile,
                    //page: options.Page,
                    //applicationDefinition: options.ApplicationDefinition,
                    //noneFile: options.None,
                    //embeddedResource: options.EmbeddedResource,
                    packageId: options.PackageId,
                    buildProps: buildProps,
                    commonSourcePackingFolder: sourcePackingFolder,
                    multiTargetingPackageInfo: multiTargetingPackageInfo,
                    // 多框架下,每个框架有自己的引用路径
                    //packageReferenceVersion: options.PackageReferenceVersion
                    logger: logger
                             );

                packer.Pack();
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }

            string ReadFile(string?file)
            {
                if (string.IsNullOrEmpty(file))
                {
                    return("");
                }

                file = Path.GetFullPath(file !);
                if (File.Exists(file))
                {
                    try
                    {
                        return(File.ReadAllText(file));
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message);
                    }
                }

                return("");
            }
        }