Skip to content

Commit

Permalink
Merge pull request #93 from dotnet-campus/t/lindexi
Browse files Browse the repository at this point in the history
开发者设置文件放在NuGet包的路径
  • Loading branch information
JasonGrass authored Aug 19, 2020
2 parents c538be8 + 7481e8d commit 4826556
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 53 deletions.
2 changes: 1 addition & 1 deletion build/Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.1.19262-alpha</Version>
<Version>0.1.19317-alpha</Version>
</PropertyGroup>
</Project>
30 changes: 30 additions & 0 deletions src/dotnetCampus.SourceYard/Assets/Current/Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</ItemGroup>
</Target>

<!--打包第一步,将会多个框架分别执行-->
<Target Name="SourceYardStep1">
<PropertyGroup>
<SourcePackingDirectory>$(IntermediateOutputPath)SourcePacking\</SourcePackingDirectory>
Expand All @@ -35,8 +36,25 @@
<PackageReferenceVersionFile>$(SourcePackingDirectory)PackageReferenceVersionFile.txt</PackageReferenceVersionFile>
<SourceProjectPackageFile>$(SourcePackingDirectory)SourceProjectPackageFile.txt</SourceProjectPackageFile>
<SourceYardPackageReferenceFile>$(SourcePackingDirectory)SourceYardPackageReferenceFile.txt</SourceYardPackageReferenceFile>

<SourceYardCompilePackageFile>$(SourcePackingDirectory)SourceYardCompilePackageFile.txt</SourceYardCompilePackageFile>
<SourceYardResourcePackageFile>$(SourcePackingDirectory)SourceYardResourcePackageFile.txt</SourceYardResourcePackageFile>
<SourceYardContentPackageFile>$(SourcePackingDirectory)SourceYardContentPackageFile.txt</SourceYardContentPackageFile>
<SourceYardNonePackageFile>$(SourcePackingDirectory)SourceYardNonePackageFile.txt</SourceYardNonePackageFile>
<SourceYardEmbeddedResourcePackageFile>$(SourcePackingDirectory)SourceYardEmbeddedResourcePackageFile.txt</SourceYardEmbeddedResourcePackageFile>
</PropertyGroup>

<ItemGroup>
<_SourceYardCompilePackage Include="%(SourceYardCompile.Identity)|%(SourceYardCompile.SourcePackagePath)"/>
<_SourceYardResourcePackage Include="%(SourceYardResource.Identity)|%(SourceYardResource.SourcePackagePath)"/>
<_SourceYardContentPackage Include="%(SourceYardContent.Identity)|%(SourceYardContent.SourcePackagePath)"/>
<_SourceYardNonePackage Include="%(SourceYardNone.Identity)|%(SourceYardNone.SourcePackagePath)"/>
<_SourceYardEmbeddedResourcePackage Include="%(SourceYardEmbeddedResource.Identity)|%(SourceYardEmbeddedResource.SourcePackagePath)"/>

<!-- 这是给 SourceFusion 预编译生成的文件加入打包 -->
<_SourceYardForSourceFusionCompilePackage Include="%(_SourceFusionIncludedCompileFile.Identity)|%(_SourceFusionIncludedCompileFile.Identity)"/>
</ItemGroup>

<PropertyGroup>

<SourceYardAuthors Condition="$(Authors) != ''">--Authors "$(Authors)"</SourceYardAuthors>
Expand Down Expand Up @@ -69,6 +87,7 @@

</Target>

<!--打包第二步,将会多个框架分别执行-->
<Target Name="SourceYardStep2">

<MakeDir Condition="!Exists($(SourcePackingDirectory))" Directories="$(SourcePackingDirectory)"></MakeDir>
Expand All @@ -95,8 +114,19 @@

<WriteLinesToFile File="$(PackageReferenceVersionFile)" Lines="@(_PackageReferenceVersion)" Overwrite="true" />
<WriteLinesToFile File="$(SourceYardPackageReferenceFile)" Lines="$(SourceYardPackageReference)" Overwrite="true"></WriteLinesToFile>

<WriteLinesToFile File="$(SourceYardCompilePackageFile)" Lines="@(_SourceYardCompilePackage)" Overwrite="true"></WriteLinesToFile>
<!-- 这是给 SourceFusion 预编译生成的文件加入打包,写入在 SourceYardCompilePackageFile 文件 -->
<WriteLinesToFile File="$(SourceYardCompilePackageFile)" Lines="@(_SourceYardForSourceFusionCompilePackage)"></WriteLinesToFile>

<WriteLinesToFile File="$(SourceYardResourcePackageFile)" Lines="@(_SourceYardResourcePackage)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceYardContentPackageFile)" Lines="@(_SourceYardContentPackage)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceYardNonePackageFile)" Lines="@(_SourceYardNonePackage)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceYardEmbeddedResourcePackageFile)" Lines="@(_SourceYardEmbeddedResourcePackage)" Overwrite="true"></WriteLinesToFile>

</Target>

<!--打包第三步,无论多框架还是单框架只执行一次-->
<Target Name="SourceYardStep3">
<Exec
Command="$(MSBuildThisFileDirectory)..\tools\net45\dotnetCampus.SourceYard.exe $(SourceMSBuildProjectFullPath) $(SourceIntermediateDirectory) $(SourcePackageOutputPath) $(SourceYardPackageVersion) --Compile $(CompileTextFile) --Resource $(ResourceTextFile) --Content $(ContentTextFile) --Page $(PageTextFile) --ApplicationDefinition $(ApplicationDefinitionTextFile) --None $(NoneTextFile) --EmbeddedResource $(EmbeddedResourceTextFile) $(SourceYardAuthors) $(SourceYardRepositoryUrl) $(SourceYardRepositoryType) $(SourceYardPackageProjectUrl) $(SourceYardCopyright) $(SourceYardDescription) $(SourceYardTitle) $(SourceYardPackageLicenseUrl) $(SourceYardPackageReleaseNotes) $(SourceYardPackageTags) $(SourceYardOwner) $(SourceYardPackageId) $(SourcePackageReferenceVersion) --SourcePackingDirectory $(SourcePackingDirectory) --TargetFrameworks &quot;$(TargetFrameworks) &quot; --TargetFramework &quot;$(TargetFramework) &quot;">
Expand Down
96 changes: 78 additions & 18 deletions src/dotnetCampus.SourceYard/Context/PackagedProjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,106 @@ namespace dotnetCampus.SourceYard.Context
class PackagedProjectFile
{
/// <inheritdoc />
public PackagedProjectFile(string compileFile, string resourceFile, string contentFile, string page, string applicationDefinition, string noneFile, string embeddedResource, string projectFolder)
public PackagedProjectFile(string compileFile, string resourceFile, string contentFile, string page,
string applicationDefinition, string noneFile, string embeddedResource, string projectFolder,
BuildProps buildProps)
{
_projectFolder = projectFolder;
_buildProps = buildProps;
ApplicationDefinition = applicationDefinition;

CompileFileList = GetFileList(compileFile);
ResourceFileList = GetFileList(resourceFile);
ContentFileList = GetFileList(contentFile);
CompileFileList = GetSourceYardPackageFileList(compileFile, SourceYardCompilePackageFile);
ResourceFileList = GetSourceYardPackageFileList(resourceFile, SourceYardResourcePackageFile);
ContentFileList = GetSourceYardPackageFileList(contentFile, SourceYardContentPackageFile);
PageList = GetFileList(page);
NoneFileList = GetFileList(noneFile);
EmbeddedResourceList = GetFileList(embeddedResource);
NoneFileList = GetSourceYardPackageFileList(noneFile, SourceYardNonePackageFile);
EmbeddedResourceList = GetSourceYardPackageFileList(embeddedResource, SourceYardEmbeddedResourcePackageFile);
}

private const string
SourceYardCompilePackageFile = "SourceYardCompilePackageFile.txt",
SourceYardResourcePackageFile = "SourceYardResourcePackageFile.txt",
SourceYardContentPackageFile = "SourceYardContentPackageFile.txt",
SourceYardNonePackageFile = "SourceYardNonePackageFile.txt",
SourceYardEmbeddedResourcePackageFile = "SourceYardEmbeddedResourcePackageFile.txt";

/// <summary>
/// 需要做源码包的项目的编译的文件
/// </summary>
public IReadOnlyList<string> CompileFileList { get; }
public IReadOnlyList<SourceYardPackageFile> CompileFileList { get; }

/// <summary>
/// 需要做源码包的项目的资源文件
/// </summary>
public IReadOnlyList<string> ResourceFileList { get; }
public IReadOnlyList<SourceYardPackageFile> ResourceFileList { get; }

/// <summary>
/// 需要做源码包项目的文件
/// </summary>
public IReadOnlyList<string> ContentFileList { get; }
public IReadOnlyList<SourceYardPackageFile> ContentFileList { get; }

/// <summary>
/// 需要做源码包项目的页面
/// </summary>
public IReadOnlyList<string> PageList { get; }
public IReadOnlyList<SourceYardPackageFile> PageList { get; }

/// <summary>
/// 嵌入文件
/// </summary>
public IReadOnlyList<string> EmbeddedResourceList { get; }
public IReadOnlyList<SourceYardPackageFile> EmbeddedResourceList { get; }

/// <summary>
/// 需要做源码包项目的文件
/// </summary>
private string ApplicationDefinition { get; }

public IReadOnlyList<string> NoneFileList { get; }
public IReadOnlyList<SourceYardPackageFile> NoneFileList { get; }

public IReadOnlyList<string> GetAllFile()
public IReadOnlyList<SourceYardPackageFile> GetAllFile()
{
return new CombineReadonlyList<string>(CompileFileList, ResourceFileList, ContentFileList, PageList,
return new CombineReadonlyList<SourceYardPackageFile>(CompileFileList, ResourceFileList, ContentFileList,
PageList,
NoneFileList, EmbeddedResourceList);
}

private List<string> GetFileList(string file)
private List<SourceYardPackageFile> GetSourceYardPackageFileList(string file,
string sourceYardPackageFile)
{
sourceYardPackageFile = Path.Combine(_buildProps.SourcePackingDirectory, sourceYardPackageFile);
var sourceYardPackageFileList = ParseSourceYardPackageFile(sourceYardPackageFile);

var fileList = GetFileList(file);
return new CombineReadonlyList<SourceYardPackageFile>(sourceYardPackageFileList, fileList).Distinct(new SourceYardPackageFileEqualityComparer()).ToList();
}

private List<SourceYardPackageFile> ParseSourceYardPackageFile(string sourceYardPackageFile)
{
var sourceYardPackageFileList = new List<SourceYardPackageFile>();
var text = File.ReadAllText(sourceYardPackageFile);

foreach (var line in text.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
var package = line.Split('|');
if (package.Length == 2)
{
var sourceFile = package[0];
var packagePath = package[1];

if (!string.IsNullOrEmpty(sourceFile))
{
sourceYardPackageFileList.Add(new SourceYardPackageFile(new FileInfo(sourceFile), packagePath));
}
}
}

return sourceYardPackageFileList;
}

private List<SourceYardPackageFile> GetFileList(string file)
{
if (string.IsNullOrEmpty(file) || !File.Exists(file))
{
return new List<string>();
return new List<SourceYardPackageFile>();
}

var fileList = File.ReadAllLines(file).ToList();
Expand All @@ -87,7 +131,7 @@ private List<string> GetFileList(string file)
}
}

return fileList;
return fileList.Select(temp => new SourceYardPackageFile(new FileInfo(temp), temp)).ToList();
}

private List<string> RemoveTempFile(List<string> fileList)
Expand All @@ -108,7 +152,8 @@ private List<string> RemoveTempFile(List<string> fileList)
return false;
});

fileList.RemoveAll(temp => IgnoreFileEndList.Any(t => temp.EndsWith(t, StringComparison.OrdinalIgnoreCase)));
fileList.RemoveAll(temp =>
IgnoreFileEndList.Any(t => temp.EndsWith(t, StringComparison.OrdinalIgnoreCase)));

return fileList;
}
Expand All @@ -118,6 +163,8 @@ private List<string> RemoveTempFile(List<string> fileList)
/// </summary>
private readonly string _projectFolder;

private readonly BuildProps _buildProps;

/// <summary>
/// 忽略的文件夹列表
/// </summary>
Expand All @@ -133,5 +180,18 @@ private List<string> RemoveTempFile(List<string> fileList)
{
".csproj.DotSettings", ".suo", ".user", ".sln.docstates", ".nupkg"
};

class SourceYardPackageFileEqualityComparer : IEqualityComparer<SourceYardPackageFile>
{
public bool Equals(SourceYardPackageFile x, SourceYardPackageFile y)
{
return x.SourceFile.FullName.Equals(y.SourceFile.FullName);
}

public int GetHashCode(SourceYardPackageFile obj)
{
return obj.SourceFile.FullName.GetHashCode();
}
}
}
}
26 changes: 26 additions & 0 deletions src/dotnetCampus.SourceYard/Context/SourceYardPackageFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.IO;

namespace dotnetCampus.SourceYard.Context
{
/// <summary>
/// 放在源代码包的文件
/// </summary>
public class SourceYardPackageFile
{
public SourceYardPackageFile(FileInfo sourceFile, string sourcePackagePath)
{
SourceFile = sourceFile;
SourcePackagePath = sourcePackagePath;
}

/// <summary>
/// 源代码的文件
/// </summary>
public FileInfo SourceFile { get; }

/// <summary>
/// 打包的路径
/// </summary>
public string SourcePackagePath { get; }
}
}
45 changes: 23 additions & 22 deletions src/dotnetCampus.SourceYard/Packer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,52 @@ public Packer(string projectFile, string intermediateDirectory,
{
Logger = new Logger();

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

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

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

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

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

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

PackagedProjectFile = new PackagedProjectFile
(
compileFile: GetFile(compileFile),
resourceFile: GetFile(resourceFile),
contentFile: GetFile(contentFile),
embeddedResource: GetFile(embeddedResource),
page: GetFile(page),
applicationDefinition: GetFile(applicationDefinition),
noneFile: GetFile(noneFile),
projectFolder: Path.GetDirectoryName(_projectFile)
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[]
Expand All @@ -72,7 +73,7 @@ public Packer(string projectFile, string intermediateDirectory,
new NuGetPacker(),
};

Logger.Message("初始化打包完成");
Logger.Message(text: "初始化打包完成");
}

internal void Pack()
Expand Down
5 changes: 4 additions & 1 deletion src/dotnetCampus.SourceYard/Utils/BuildProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using dotnetCampus.Configurations;
using dotnetCampus.Configurations.Core;
using dotnetCampus.SourceYard.Context;

namespace dotnetCampus.SourceYard.Utils
{
Expand Down Expand Up @@ -142,8 +143,10 @@ public void SetSourcePackingDirectory(string packingDirectory)

var sourceYardPackageReferenceFile = Path.Combine(packingDirectory, "SourceYardPackageReferenceFile.txt");

List<string> sourceYardPackageReferenceList = File.ReadAllLines(sourceYardPackageReferenceFile).Where(temp=>!string.IsNullOrEmpty(temp)).ToList();
List<string> sourceYardPackageReferenceList = File.ReadAllLines(sourceYardPackageReferenceFile).Where(temp => !string.IsNullOrEmpty(temp)).ToList();
SourceYardPackageReferenceList = sourceYardPackageReferenceList;

var sourceYardCompilePackageFile = Path.Combine(packingDirectory, "SourceYardCompilePackageFile.txt");
}

/// <summary>
Expand Down
Loading

0 comments on commit 4826556

Please sign in to comment.