コード例 #1
0
ファイル: Packer.cs プロジェクト: getandplay/SourceYard
        public Packer(string projectFile, string intermediateDirectory,
                      string packageOutputPath, string packageVersion, string compileFile, string resourceFile,
                      string contentFile, string page, string applicationDefinition, string noneFile, string embeddedResource,
                      BuildProps buildProps)
        {
            Logger = new Logger();

            if (string.IsNullOrEmpty(projectFile) || !File.Exists(projectFile))
            {
                Logger.Error($"无法从{projectFile}找到项目文件");
                return;
            }

            if (string.IsNullOrEmpty(intermediateDirectory))
            {
                // 这时的文件夹可以不存在
                Logger.Error("无法解析文件夹 " + intermediateDirectory);
                return;
            }

            if (string.IsNullOrEmpty(packageOutputPath))
            {
                Logger.Error("打包输出文件夹不能为空");
                return;
            }

            if (string.IsNullOrEmpty(packageVersion))
            {
                Logger.Error("打包版本不能为空");
                return;
            }

            _projectFile           = Path.GetFullPath(projectFile);
            _intermediateDirectory = Path.GetFullPath(intermediateDirectory);
            _packageOutputPath     = Path.GetFullPath(packageOutputPath);
            _packageVersion        = packageVersion;
            BuildProps             = buildProps;

            PackagedProjectFile = new PackagedProjectFile
                                  (
                compileFile: GetFile(compileFile),
                resourceFile: GetFile(resourceFile),
                contentFile: GetFile(contentFile),
                embeddedResource: GetFile(embeddedResource),
                page: GetFile(page),
                applicationDefinition: GetFile(applicationDefinition),
                noneFile: GetFile(noneFile)
                                  );

            _packers = new IPackFlow[]
            {
                new SourcePacker(),
                new AssetsPacker(),
                new ItemGroupPacker(),
                new NuspecFileGenerator(),
                new NuGetPacker(),
            };
        }
コード例 #2
0
ファイル: Packer.cs プロジェクト: dotnet-campus/SourceYard
        public Packer
        (
            string projectFile,
            string intermediateDirectory,
            string packageOutputPath,
            string packageVersion,
            string?packageId,
            BuildProps buildProps,
            DirectoryInfo commonSourcePackingFolder,
            MultiTargetingPackageInfo multiTargetingPackageInfo,
            Logger logger
        )
        {
            Logger = logger;

            Logger.Message(message: "初始化打包");

            if (string.IsNullOrEmpty(value: projectFile) || !File.Exists(path: projectFile))
            {
                Logger.Error(message: $"无法从{projectFile}找到项目文件");
                return;
            }

            if (string.IsNullOrEmpty(value: intermediateDirectory))
            {
                // 这时的文件夹可以不存在
                Logger.Error(message: "无法解析文件夹 " + intermediateDirectory);
                return;
            }

            if (string.IsNullOrEmpty(value: packageOutputPath))
            {
                Logger.Error(message: "打包输出文件夹不能为空");
                return;
            }

            if (string.IsNullOrEmpty(value: packageVersion))
            {
                Logger.Error(message: "打包版本不能为空");
                return;
            }

            _projectFile               = Path.GetFullPath(path: projectFile);
            _intermediateDirectory     = Path.GetFullPath(path: intermediateDirectory);
            _packageOutputPath         = Path.GetFullPath(path: packageOutputPath);
            _packageVersion            = packageVersion;
            _multiTargetingPackageInfo = multiTargetingPackageInfo;
            BuildProps = buildProps;
            PackageId  = packageId;

            PackagedProjectFile = new PackagedProjectFile
                                  (
                commonSourcePackingFolder,
                //compileFile: GetFile(file: compileFile),
                //resourceFile: GetFile(file: resourceFile),
                //contentFile: GetFile(file: contentFile),
                //embeddedResource: GetFile(file: embeddedResource),
                //page: GetFile(file: page),
                //applicationDefinition: GetFile(file: applicationDefinition),
                //noneFile: GetFile(file: noneFile),
                projectFolder: Path.GetDirectoryName(path: _projectFile) !,
                buildProps: buildProps
                                  );

            _packers = new IPackFlow[]
            {
                new SourcePacker(),
                new AssetsPacker(),
                new ItemGroupPacker(),
                new NuspecFileGenerator(),
                new NuGetPacker(),
            };

            Logger.Message(message: "初始化打包完成");
        }
コード例 #3
0
ファイル: Packer.cs プロジェクト: getandplay/SourceYard
        internal void Pack()
        {
            var packingFolder = _intermediateDirectory;

            PrepareEmptyDirectory(packingFolder);

            var projectFile = _projectFile;

            var projectName = Path.GetFileNameWithoutExtension(projectFile);

            if (string.IsNullOrEmpty(projectName))
            {
                Logger.Error("从项目文件无法拿到项目文件名 " + projectFile);
                return;
            }

            var projectFolder = Path.GetDirectoryName(projectFile);

            if (string.IsNullOrEmpty(projectFolder))
            {
                Logger.Error("无法拿到项目文件所在文件夹");
                return;
            }

            //Directory.Build.props
            var buildProps = BuildProps;

            if (string.IsNullOrWhiteSpace(projectName))
            {
                Logger.Error($"无法从 {projectFile} 解析出正确的项目名称。");
                return;
            }

            IPackFlow current = null;

            try
            {
                foreach (var packer in _packers)
                {
                    current = packer;
                    var context = new PackingContext
                                  (
                        Logger,
                        projectFile,
                        projectName,
                        _packageVersion,
                        _packageOutputPath,
                        packingFolder,
                        PackagedProjectFile
                                  )
                    {
                        BuildProps = buildProps,
                    };
                    packer.Pack(context);
                }
            }
            catch (PackingException ex)
            {
                Logger.Error(ex);
            }
            catch (Exception ex)
            {
                Logger.Error($"生成源码包: {current?.GetType().Name}: {ex}");
            }
        }