public PackagedProjectFile(DirectoryInfo commonSourcePackingFolder, string projectFolder, BuildProps buildProps) { // 通过 commonSourcePackingFolder 可以拿到对应的输出文件路径 string compileFile = GetFile("CompileFile.txt"); string resourceFile = GetFile("ResourceFile.txt"); string contentFile = GetFile("ContentFile.txt"); string page = GetFile("PageFile.txt"); string applicationDefinition = GetFile("ApplicationDefinitionFile.txt"); string noneFile = GetFile("NoneFile.txt"); string embeddedResource = GetFile("EmbeddedResourceFile.txt"); _projectFolder = projectFolder; _buildProps = buildProps; ApplicationDefinition = applicationDefinition; CompileFileList = GetSourceYardPackageFileList(compileFile, SourceYardCompilePackageFile); ResourceFileList = GetSourceYardPackageFileList(resourceFile, SourceYardResourcePackageFile); ContentFileList = GetSourceYardPackageFileList(contentFile, SourceYardContentPackageFile); PageList = GetFileList(page); NoneFileList = GetSourceYardPackageFileList(noneFile, SourceYardNonePackageFile); EmbeddedResourceList = GetSourceYardPackageFileList(embeddedResource, SourceYardEmbeddedResourcePackageFile); string GetFile(string fileName) { return(Path.Combine(commonSourcePackingFolder.FullName, fileName)); } }
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(), }; }
public NuspecPackage Parse(XElement element, string id, string title, string version, BuildProps buildProps) { if (buildProps == null) { buildProps = new BuildProps(); } var authors = GetAuthors(element); //??"lindexi";//找不到就用我名字 var owner = GetOwners(element) ?? authors; if (string.IsNullOrEmpty(authors)) { authors = owner; } authors = authors ?? buildProps.Authors ?? buildProps.Company; owner = owner ?? authors; var description = GetDescription(element) ?? buildProps.Description; var copyright = GetCopyright(element) ?? buildProps.Copyright; var packageLicenseUrl = GetPackageLicenseUrl(element) ?? buildProps.PackageProjectUrl; var packageList = GetPackageReference(element); packageList.AddRange(GetProjectReference(element, version)); var packageProjectUrl = GetPackageProjectUrl(element) ?? buildProps.PackageProjectUrl; var packageIconUrl = GetPackageIconUrl(element); var packageTags = GetPackageTags(element); var packageReleaseNotes = GetPackageReleaseNotes(element); var nuspecMetadata = new NuspecMetadata { Id = id, Copyright = copyright, PackageLicenseUrl = packageLicenseUrl, Version = version, Dependencies = GetDependencies(packageList), PackageProjectUrl = packageProjectUrl, PackageIconUrl = packageIconUrl, PackageTags = packageTags, PackageReleaseNotes = packageReleaseNotes, Title = title, Authors = authors, Owner = owner, Description = description, }; var nuspecPackage = new NuspecPackage() { NuspecMetadata = nuspecMetadata }; return(nuspecPackage); }
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(""); } }
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: "初始化打包完成"); }
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(""); } }