未验证 提交 49179b1e 编写于 作者: L lindexi 提交者: GitHub

Merge pull request #113 from dotnet-campus/t/lindexi_Framework

增加分版本的package引用和framework引用
......@@ -9,7 +9,7 @@
<!-- 默认是 true,如果指定为 false,那么项目编译输出的 dll 文件将不会被打包到 NuGet 包中。 -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<Description>Add a NuGet package only for dll reference? By using dotnetCampus.SourceYard, you can pack a NuGet package with source code. By installing the new source code package, all source codes behaviors just like it is in your project.</Description>
<Copyright>Copyright (c) 2020 dotnet-campus</Copyright>
<Copyright>Copyright (c) 2019-2021 dotnet-campus</Copyright>
<PackageProjectUrl>https://github.com/dotnet-campus/dotnetCampus.SourceYard</PackageProjectUrl>
<RepositoryUrl>https://github.com/dotnet-campus/dotnetCampus.SourceYard.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
......
......@@ -44,4 +44,8 @@ If you would like to contribute, feel free to create a [Pull Request](https://gi
## Roadmap
Check out this [Roadmap](https://github.com/dotnet-campus/SourceYard/projects/1) to learn about our development plans for 2020.
\ No newline at end of file
Check out this [Roadmap](https://github.com/dotnet-campus/SourceYard/projects/1) to learn about our development plans for 2021.
## Thanks
- [@Zhuangkh](https://github.com/Zhuangkh)
\ No newline at end of file
<Project>
<PropertyGroup>
<Version>0.1.19372-alpha</Version>
<Version>0.1.19393-alpha13</Version>
</PropertyGroup>
</Project>
# 行为和配置
## 术语
源代码包: 将源代码打包到 NuGet 文件,也就是 SourceYard 工具的输出文件
库项目: 用于打出源代码包的项目
目标项目: 安装上某个源代码包的项目
## 特殊配置
在 SourceYard 打出的源代码包中,可以通过一些特殊的配置实现源代码包特殊的功能
### DisableSourcePackageAutoPrivateAssets
禁止自动配置目标全部源代码包自动设置 PrivateAssets 属性,默认的源代码将会自动添加如下代码
```xml
<ItemGroup Condition="$(DisableSourcePackageAutoPrivateAssets) != 'true'">
<!-- 用于修复设置了 DevelopmentDependency 将不自动添加依赖 -->
<!-- 参阅 https://github.com/dotnet-campus/SourceYard/issues/112 -->
<PackageReference Update="#(PackageId)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>all</IncludeAssets>
</PackageReference>
</ItemGroup>
```
可以通过在 `目标项目` 上设置 DisableSourcePackageAutoPrivateAssets 属性为 true 禁用当前项目全部安装的源代码包自动设置
以上的 `#(PackageId)` 就是对应的安装的源代码包,如 `TheLib.Source`
如需要对具体某个源代码包进行配置,请自行设置更新覆盖即可
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<Import Condition="Exists('obj\AppUsingSource.csproj.nuget.g.props') " Project="obj\AppUsingSource.csproj.nuget.g.props" />
<!--<Import Condition="Exists('obj\AppUsingSource.csproj.nuget.g.props') " Project="obj\AppUsingSource.csproj.nuget.g.props" />-->
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>net45;net5.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TheLib.Source" Version="1.0.2" />
<PackageReference Include="TheLib.Source" Version="1.0.3-alpha06" />
</ItemGroup>
<Import Condition="Exists('obj\AppUsingSource.csproj.nuget.g.targets') " Project="obj\AppUsingSource.csproj.nuget.g.targets" />
<!--<Import Condition="Exists('obj\AppUsingSource.csproj.nuget.g.targets') " Project="obj\AppUsingSource.csproj.nuget.g.targets" />-->
</Project>
using System;
using System.Windows;
using TheLib;
namespace AppUsingSource
......@@ -8,6 +9,13 @@ namespace AppUsingSource
static void Main(string[] args)
{
var money = new Money(12312);
var v = (money, "123");
Console.WriteLine(v);
#if NET45
var dependencyObject = new DependencyObject();
#endif
Console.WriteLine(money.ToCapital());
Console.ReadLine();
}
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net45</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="dotnetCampus.SourceYard" Version="0.1.19370-alpha01">
<PackageReference Include="dotnetCampus.SourceYard" Version="0.1.19393-alpha13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- <Target Name="GallikufawhaGebalule" AfterTargets="Build"> -->
<!-- ~1~ <Warning Text="PackingDirectory: $(PackingDirectory)" /> @1@ -->
<!-- <Warning Text="IntermediateOutputPath: $(IntermediateOutputPath)" /> -->
<!-- </Target> -->
<ItemGroup Condition="'$(TargetFramework)'=='net45'">
<Reference Include="WindowsBase"></Reference>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net5.0'">
<PackageReference Include="dotnetCampus.CommandLine" Version="3.3.0" />
</ItemGroup>
<!--<Target Name="_SourceYardFrameworkAssets"
AfterTargets="ResolveReferences">
<ItemGroup>
<_TfmSpecificFrameworkAssemblyReferences Include="@(ReferencePath->'%(OriginalItemSpec)')"
Condition="'%(ReferencePath.Pack)' != 'false' AND '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}'">
</_TfmSpecificFrameworkAssemblyReferences>
</ItemGroup>
<Warning Text="$(TargetFramework):@(_TfmSpecificFrameworkAssemblyReferences)"/>
</Target>-->
<ItemGroup>
<SourceYardExcludeFileItem Include="foo.coin" />
<SourceYardExcludeFileItem Include="Resource\F1.md" />
</ItemGroup>
</Project>
</Project>
\ No newline at end of file
<Project>
<PropertyGroup>
<Version>1.0.3</Version>
<Version>1.0.3-alpha06</Version>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -3,6 +3,17 @@
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<PropertyGroup>
<!-- 用于给多框架存放各个框架的信息的文件的文件夹,各个框架将会在写入到各自的文件里面 -->
<!-- 选择 BaseIntermediateOutputPath 是因为开发者可以配置不同的框架采用不同的 obj 文件夹,但是对于不同的框架,大部分都是使用相同的 BaseIntermediateOutputPath 文件夹 -->
<_SourceYardMultiTargetingPackageInfoFolder>$(BaseIntermediateOutputPath)$(Configuration)\SourceYardMultiTargetingPackageInfoFolder\</_SourceYardMultiTargetingPackageInfoFolder>
<!--
输出形式如:
- obj\Debug\SourceYardMultiTargetingPackageInfoFolder\net45.txt
- obj\Debug\SourceYardMultiTargetingPackageInfoFolder\net5.0.txt
-->
</PropertyGroup>
<!-- 打包核心 -->
......@@ -16,9 +27,24 @@
</ItemGroup>
</Target>
<Target Name="_SourceYardFrameworkAssets"
AfterTargets="ResolveReferences">
<ItemGroup>
<!-- 参考 [增加分版本的package引用和framework引用 by Zhuangkh · Pull Request #111 · dotnet-campus/SourceYard](https://github.com/dotnet-campus/SourceYard/pull/111 ) -->
<_TfmSpecificFrameworkAssemblyReferences Include="@(ReferencePath->'%(OriginalItemSpec)')"
Condition="'%(ReferencePath.Pack)' != 'false' AND '%(ReferencePath.ResolvedFrom)' == '{TargetFrameworkDirectory}'">
</_TfmSpecificFrameworkAssemblyReferences>
</ItemGroup>
</Target>
<!--打包第一步,将会多个框架分别执行-->
<Target Name="SourceYardStep1">
<PropertyGroup>
<!-- 用于将各个框架的信息写入的文件 -->
<_SourceYardMultiTargetingPackageInfoFile>$(_SourceYardMultiTargetingPackageInfoFolder)$(TargetFramework).txt</_SourceYardMultiTargetingPackageInfoFile>
<!-- 这里不能使用 $(PackingDirectory) 属性,原因是此属性在未打包时是空 -->
<!-- 对于多框架来说,这里的 IntermediateOutputPath 路径格式如 obj\Debug\net45\ -->
<SourcePackingDirectory>$(IntermediateOutputPath)SourcePacking\</SourcePackingDirectory>
<CompileTextFile>$(SourcePackingDirectory)CompileFile.txt</CompileTextFile>
......@@ -34,6 +60,7 @@
<PackageReleaseNotesFile>$(SourcePackingDirectory)PackageReleaseNotesFile.txt</PackageReleaseNotesFile>
<PackageReferenceVersionFile>$(SourcePackingDirectory)PackageReferenceVersionFile.txt</PackageReferenceVersionFile>
<FrameworkReferenceVersionFile>$(SourcePackingDirectory)FrameworkReferenceVersionFile.txt</FrameworkReferenceVersionFile>
<SourceProjectPackageFile>$(SourcePackingDirectory)SourceProjectPackageFile.txt</SourceProjectPackageFile>
<SourceYardPackageReferenceFile>$(SourcePackingDirectory)SourceYardPackageReferenceFile.txt</SourceYardPackageReferenceFile>
......@@ -91,10 +118,9 @@
<SourceYardPackageId Condition="'$(PackageId)' != ''">--PackageId "$(PackageId) "</SourceYardPackageId>
<SourceMSBuildProjectFullPath>-p "$(MSBuildProjectFullPath) "</SourceMSBuildProjectFullPath>
<SourceIntermediateDirectory>-i "$(SourcePackingDirectory)Package "</SourceIntermediateDirectory>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' != ''">-n "$(PackageOutputPath) "</SourcePackageOutputPath>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' == '' and $(OutputPath) != ''">-n "$(OutputPath) "</SourcePackageOutputPath>
<SourcePackageReferenceVersion>--PackageReferenceVersion "$(PackageReferenceVersionFile)"</SourcePackageReferenceVersion>
</PropertyGroup>
......@@ -105,8 +131,14 @@
<!--打包第二步,将会多个框架分别执行-->
<Target Name="SourceYardStep2">
<MakeDir Condition="!Exists($(_SourceYardMultiTargetingPackageInfoFolder))" Directories="$(_SourceYardMultiTargetingPackageInfoFolder)"></MakeDir>
<MakeDir Condition="!Exists($(SourcePackingDirectory))" Directories="$(SourcePackingDirectory)"></MakeDir>
<!-- 写入框架信息 -->
<!--为了支持多框架项目,需要将当前的路径写入保存-->
<WriteLinesToFile File="$(_SourceYardMultiTargetingPackageInfoFile)" Lines="$(SourcePackingDirectory)" Overwrite="true"/>
<WriteLinesToFile File="$(CompileTextFile)" Lines="@(Compile)" Overwrite="true" />
<WriteLinesToFile File="$(ResourceTextFile)" Lines="@(Resource)" Overwrite="true" />
<WriteLinesToFile File="$(ContentTextFile)" Lines="@(Content)" Overwrite="true" />
......@@ -128,6 +160,7 @@
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;RepositoryUrl;$(RepositoryUrl);"></WriteLinesToFile>
<WriteLinesToFile File="$(PackageReferenceVersionFile)" Lines="@(_PackageReferenceVersion)" Overwrite="true" />
<WriteLinesToFile File="$(FrameworkReferenceVersionFile)" Lines="@(_TfmSpecificFrameworkAssemblyReferences)" Overwrite="true"/>
<WriteLinesToFile File="$(SourceYardPackageReferenceFile)" Lines="$(SourceYardPackageReference)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceYardCompilePackageFile)" Lines="@(_SourceYardCompilePackage)" Overwrite="true"></WriteLinesToFile>
......@@ -152,7 +185,7 @@
<!--打包第三步,无论多框架还是单框架只执行一次-->
<Target Name="SourceYardStep3">
<!-- 开发者自己有指定路径,但是路径里面不存在应用 -->
<Error Text="Can not find SourceYardApplicationFilePath $(SourceYardApplicationFilePath)" Condition="'$(SourceYardApplicationFilePath)' != '' And !Exists($(SourceYardApplicationFilePath))"/>
......@@ -166,7 +199,7 @@
</PropertyGroup>
<Exec
Command="$(SourceYardApplicationFilePath) $(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;">
Command="$(SourceYardApplicationFilePath) $(SourceMSBuildProjectFullPath) $(SourcePackageOutputPath) $(SourceYardPackageVersion) $(SourceYardAuthors) $(SourceYardRepositoryUrl) $(SourceYardRepositoryType) $(SourceYardPackageProjectUrl) $(SourceYardCopyright) $(SourceYardDescription) $(SourceYardTitle) $(SourceYardPackageLicenseUrl) $(SourceYardPackageReleaseNotes) $(SourceYardPackageTags) $(SourceYardOwner) $(SourceYardPackageId) --TargetFrameworks &quot;$(TargetFrameworks) &quot; --TargetFramework &quot;$(TargetFramework) &quot; --MultiTargetingPackageInfoFolder &quot;$(_SourceYardMultiTargetingPackageInfoFolder) &quot;">
</Exec>
<Message Text="Finish SourceYardStep3"></Message>
......
<Project>
<ItemGroup Condition="$(DisableSourcePackageAutoPrivateAssets) != 'true'">
<!-- 用于修复设置了 DevelopmentDependency 将不自动添加依赖 -->
<!-- 参阅 https://github.com/dotnet-campus/SourceYard/issues/112 -->
<PackageReference Update="#(PackageId)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>all</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition="!$(DefineConstants.Contains('#(PackageGuid)SOURCE_REFERENCE')) ">
<_#(PackageGuid)ImportInWpfTempProjectDependsOn>
_#(PackageGuid)IncludeSourceCodes
......
......@@ -10,11 +10,11 @@ namespace dotnetCampus.SourceYard.Cli
[Option('p', "project", Description = "The full path of the project file.")]
public string ProjectFile { get; set; } = null!;
/// <summary>
/// 临时的文件夹的路径
/// </summary>
[Option('i', "intermediate-directory", Description = "The relative path of the project intermediate output path, commonly the 'obj' folder and value in 'obj'.")]
public string IntermediateDirectory { get; set; } = null!;
///// <summary>
///// 临时的文件夹的路径
///// </summary>
//[Option('i', "intermediate-directory", Description = "The relative path of the project intermediate output path, commonly the 'obj' folder and value in 'obj'.")]
//public string IntermediateDirectory { get; set; } = null!;
/// <summary>
/// 打包输出的文件夹
......@@ -30,29 +30,29 @@ namespace dotnetCampus.SourceYard.Cli
Description = "The package version value.")]
public string PackageVersion { get; set; } = "1.0.0";
/// <summary>
/// 项目进行编译的文件的列表,因为参数太多,需要将参数写到文件
/// </summary>
[Option(longName: "Compile", Description = "编译的文件")]
public string? CompileFile { get; set; }
///// <summary>
///// 项目进行编译的文件的列表,因为参数太多,需要将参数写到文件
///// </summary>
//[Option(longName: "Compile", Description = "编译的文件")]
//public string? CompileFile { get; set; }
/// <summary>
/// 存放资源文件参数的文件
/// </summary>
[Option(longName: "Resource", Description = "资源文件")]
public string? ResourceFile { get; set; }
///// <summary>
///// 存放资源文件参数的文件
///// </summary>
//[Option(longName: "Resource", Description = "资源文件")]
//public string? ResourceFile { get; set; }
[Option(longName: "Content")]
public string? ContentFile { get; set; }
//[Option(longName: "Content")]
//public string? ContentFile { get; set; }
[Option(longName: "Page")]
public string? Page { get; set; }
//[Option(longName: "Page")]
//public string? Page { get; set; }
[Option(longName: "None")]
public string? None { get; set; }
//[Option(longName: "None")]
//public string? None { get; set; }
[Option(longName: "EmbeddedResource")]
public string? EmbeddedResource { get; set; }
//[Option(longName: "EmbeddedResource")]
//public string? EmbeddedResource { get; set; }
/// <summary>
/// 打包的公司内容
......@@ -82,8 +82,8 @@ namespace dotnetCampus.SourceYard.Cli
[Option(longName: "DescriptionFile")]
public string? DescriptionFile { get; set; }
[Option(longName: "ApplicationDefinition")]
public string? ApplicationDefinition { get; set; }
//[Option(longName: "ApplicationDefinition")]
//public string? ApplicationDefinition { get; set; }
[Option(longName: "Owner")]
public string? Owner { get; set; }
......@@ -106,19 +106,25 @@ namespace dotnetCampus.SourceYard.Cli
[Option(longName: "PackageId")]
public string? PackageId { get; set; }
[Option(longName: "PackageReferenceVersion")]
public string? PackageReferenceVersion { get; set; }
//[Option(longName: "PackageReferenceVersion")]
//public string? PackageReferenceVersion { get; set; }
/// <summary>
/// 打包用到的文件夹
/// </summary>
[Option(longName: "SourcePackingDirectory")]
public string SourcePackingDirectory { get; set; } = null!;
///// <summary>
///// 打包用到的文件夹
///// </summary>
//[Option(longName: "SourcePackingDirectory")]
//public string SourcePackingDirectory { get; set; } = null!;
[Option(longName: "TargetFramework")]
public string? TargetFramework { get; set; }
[Option(longName: "TargetFrameworks")]
public string? TargetFrameworks { get; set; }
/// <summary>
/// 多框架信息存放的文件夹,即使是单框架项目也会存在此文件夹
/// </summary>
[Option("MultiTargetingPackageInfoFolder")]
public string MultiTargetingPackageInfoFolder { set; get; } = null!;
}
}
......@@ -58,6 +58,14 @@ namespace dotnetCampus.SourceYard.Context
PackagedProjectFile PackagedProjectFile { get; }
BuildProps BuildProps { get; }
string PackageReferenceVersion { get; }
/// <summary>
/// 多框架的打包内容
/// </summary>
/// 路径是 obj\Debug\SourceYardMultiTargetingPackageInfoFolder
/// 内容如下
/// - obj\Debug\SourceYardMultiTargetingPackageInfoFolder\net45.txt
/// - obj\Debug\SourceYardMultiTargetingPackageInfoFolder\net5.0.txt
MultiTargetingPackageInfo MultiTargetingPackageInfo { get; }
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dotnetCampus.SourceYard.Cli;
namespace dotnetCampus.SourceYard.Context
{
class MultiTargetingPackageInfo
{
public MultiTargetingPackageInfo(Options options)
: this(new DirectoryInfo(options.MultiTargetingPackageInfoFolder), options.TargetFrameworks)
{
}
public MultiTargetingPackageInfo(DirectoryInfo multiTargetingPackageInfoFolder, string? targetFrameworks)
{
MultiTargetingPackageInfoFolder = multiTargetingPackageInfoFolder;
var folder = multiTargetingPackageInfoFolder.FullName;
var targetFrameworkPackageInfoList = new List<TargetFrameworkPackageInfo>();
foreach (var file in Directory.GetFiles(folder, "*.txt"))
{
var packageInfo = File.ReadAllText(file!);
var sourcePackingFolder = packageInfo.Trim('\r', '\n');
sourcePackingFolder = Path.GetFullPath(sourcePackingFolder);
// 判断此文件是否合法
// 判断方法如获取 CompileFile.txt 是否存在
var compileFile = Path.Combine(sourcePackingFolder, "CompileFile.txt");
if (File.Exists(compileFile))
{
var targetFramework = Path.GetFileNameWithoutExtension(file);
targetFrameworkPackageInfoList.Add(new TargetFrameworkPackageInfo(targetFramework,
new DirectoryInfo(sourcePackingFolder)));
}
}
TargetFrameworkPackageInfoList = targetFrameworkPackageInfoList;
var validTargetFrameworkPackageInfoList = targetFrameworkPackageInfoList.ToList();
validTargetFrameworkPackageInfoList.RemoveAll(t =>
{
if (t.IsValid is false)
{
return true;
}
if (targetFrameworks != null && !string.IsNullOrWhiteSpace(targetFrameworks))
{
// 对于单框架,也许 targetFrameworks 的值是空字符串
if (!targetFrameworks.Contains(t.TargetFramework))
{
// 例外项是什么?如 TargetFrameworks 包含 4.5.1 版本,但是 TargetFramework 是 4.5 版本,此时判断是对的
// 但是这里其实不需要精确判断,有 4.5.1 版本,自然就支持 4.5 和以下
// 是否让 TargetFramework 存放空字符串?也许,但是过不了 t.IsValid 的值
return true;
}
}
return false;
});
ValidTargetFrameworkPackageInfoList = validTargetFrameworkPackageInfoList;
}
public DirectoryInfo MultiTargetingPackageInfoFolder { get; }
public IReadOnlyList<TargetFrameworkPackageInfo> ValidTargetFrameworkPackageInfoList { get; }
public IReadOnlyList<TargetFrameworkPackageInfo> TargetFrameworkPackageInfoList { get; }
}
}
\ No newline at end of file
......@@ -11,11 +11,18 @@ namespace dotnetCampus.SourceYard.Context
/// </summary>
class PackagedProjectFile
{
/// <inheritdoc />
public PackagedProjectFile(string compileFile, string resourceFile, string contentFile, string page,
string applicationDefinition, string noneFile, string embeddedResource, string projectFolder,
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;
......@@ -26,6 +33,11 @@ namespace dotnetCampus.SourceYard.Context
PageList = GetFileList(page);
NoneFileList = GetSourceYardPackageFileList(noneFile, SourceYardNonePackageFile);
EmbeddedResourceList = GetSourceYardPackageFileList(embeddedResource, SourceYardEmbeddedResourcePackageFile);
string GetFile(string fileName)
{
return Path.Combine(commonSourcePackingFolder.FullName, fileName);
}
}
private const string
......@@ -182,7 +194,7 @@ namespace dotnetCampus.SourceYard.Context
/// </summary>
private static IList<string> IgnoreFileEndList { get; } = new List<string>()
{
".csproj.DotSettings", ".suo", ".user", ".sln.docstates",
".csproj.DotSettings", ".suo", ".user", ".sln.docstates",
".nupkg",
// 忽略原因请看 https://github.com/dotnet-campus/SourceYard/issues/98
"launchSettings.json"
......
......@@ -8,12 +8,12 @@ namespace dotnetCampus.SourceYard.Context
{
public PackingContext(ILogger logger, string projectFile,
string projectName, string? packageId, string packageVersion, string packageOutputPath, string packingFolder,
PackagedProjectFile packagedProjectFile, string packageReferenceVersion)
PackagedProjectFile packagedProjectFile, MultiTargetingPackageInfo multiTargetingPackageInfo)
{
Logger = logger;
ProjectFile = projectFile;
ProjectFolder = Path.GetDirectoryName(projectFile);
ProjectFolder = Path.GetDirectoryName(projectFile)!;
ProjectName = projectName;
packageId = packageId?.Trim() ?? "";
if (string.IsNullOrEmpty(packageId))
......@@ -28,7 +28,7 @@ namespace dotnetCampus.SourceYard.Context
PackageGuid = projectName.Replace(".", "");
PackingFolder = packingFolder;
PackagedProjectFile = packagedProjectFile;
PackageReferenceVersion = packageReferenceVersion;
MultiTargetingPackageInfo = multiTargetingPackageInfo;
PackageVersion = packageVersion;
PackageOutputPath = packageOutputPath;
}
......@@ -46,7 +46,7 @@ namespace dotnetCampus.SourceYard.Context
public string ProjectName { get; }
/// <inheritdoc />
public string PackageId { get; set; }
public string PackageId { get; }
/// <inheritdoc />
public string PackageGuid { get; set; }
......@@ -61,8 +61,7 @@ namespace dotnetCampus.SourceYard.Context
public string PackingFolder { get; }
public PackagedProjectFile PackagedProjectFile { get; }
public string PackageReferenceVersion { get; }
public MultiTargetingPackageInfo MultiTargetingPackageInfo { get; }
public BuildProps BuildProps { get; set; } = null!;
}
}
using System.IO;
namespace dotnetCampus.SourceYard.Context
{
class TargetFrameworkPackageInfo
{
public TargetFrameworkPackageInfo(string targetFramework, DirectoryInfo sourcePackingFolder)
{
TargetFramework = targetFramework;
SourcePackingFolder = sourcePackingFolder;
}
public bool IsValid
{
get { return _isValid ??= GetIsValid(); }
}
public string TargetFramework { get; }
public DirectoryInfo SourcePackingFolder { get; }
private bool GetIsValid()
{
// 判断此文件是否合法
// 判断方法如获取 CompileFile.txt 是否存在
var compileFile = Path.Combine(SourcePackingFolder.FullName, "CompileFile.txt");
return File.Exists(compileFile);
}
private bool? _isValid;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml.Serialization;
using dotnetCampus.SourceYard.Context;
using dotnetCampus.SourceYard.PackFlow.Nuspec;
using dotnetCampus.SourceYard.PackFlow.NuspecFiles;
using dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts;
namespace dotnetCampus.SourceYard.PackFlow
{
......@@ -86,91 +83,11 @@ namespace dotnetCampus.SourceYard.PackFlow
PackageLicenseUrl = buildProps.PackageLicenseUrl,
PackageTags = buildProps.PackageTags,
PackageReleaseNotes = buildProps.PackageReleaseNotes,
Dependencies = GetDependencies(context.PackageReferenceVersion,
buildProps.SourceYardPackageReferenceList,
buildProps.SourceYardExcludePackageReferenceList),
Dependencies = DependenciesParser.GetDependencies(context),
FrameworkAssemblies = DependenciesParser.GetFrameworkAssemblies(context),
Repository = repository
}
};
}
/// <summary>
/// 获取依赖
/// </summary>
/// <param name="contextPackageVersion">引用的NuGet包于版本号</param>
/// <param name="sourceYardPackageReferenceList">源代码包</param>
/// <param name="excludePackageReferenceList">排除的依赖</param>
/// <returns></returns>
private List<NuspecDependency> GetDependencies(string contextPackageVersion,
List<string> sourceYardPackageReferenceList, List<string> excludePackageReferenceList)
{
var nuspecDependencyList = ParserPackageVersion(contextPackageVersion, sourceYardPackageReferenceList);
// 如果在排除列表就移除
if (excludePackageReferenceList.Count > 0)
{
var excludeList = new HashSet<string>(excludePackageReferenceList);
nuspecDependencyList.RemoveAll(temp => excludeList.Contains(temp.Id));
}
return nuspecDependencyList;
}
private List<NuspecDependency> ParserPackageVersion(string packageVersionFile,
List<string> sourceYardPackageReferenceList)
{
var nuspecDependencyList = new List<NuspecDependency>();
var packageVersionRegex = new Regex(@"Name='(\S+)' Version='([\S|\-]+)' PrivateAssets='(\S*)'");
using (var stream = File.OpenText(packageVersionFile))
{
string? line;
while ((line = stream.ReadLine()) != null)
{
var match = packageVersionRegex.Match(line);
if (match.Success)
{
var name = match.Groups[1].Value;
var version = match.Groups[2].Value;
var privateAssets = match.Groups[3].Value;
// 在源代码包如果项目引用的是 private asset 的库,那么就不应该添加引用
// 因为源代码是没有框架的依赖,对 sdk 带的库也不添加
var isPrivateAssetsAll = privateAssets.IndexOf("all", StringComparison.OrdinalIgnoreCase) >= 0;
// net45 没有下面方法
//var isPrivateAssetsAll = privateAssets.Contains("all", comparer);
// 解决 https://github.com/dotnet-campus/SourceYard/issues/60
// 即使有某个包标记了使用 private asset 是 All 的,但是这个包是一个源代码包,那么打包的时候就需要添加他的引用依赖
var includeInSourceYardPackageReference = sourceYardPackageReferenceList.Any(temp => temp.Equals(name, StringComparison.OrdinalIgnoreCase));
if ((!isPrivateAssetsAll || includeInSourceYardPackageReference)
&& !SDKNuget.Contains(name))
{
nuspecDependencyList.Add(new NuspecDependency()
{
Id = name,
Version = version
});
}
}
else
{
_log.Warning($"项目所引用的 NuGet 包包含有无法识别的格式,包信息:{line}");
}
}
}
return nuspecDependencyList;
}
/// <summary>
/// 包含在 sdk 的库,这些库不应该加入引用
/// </summary>
private string[] SDKNuget { get; } = new[]
{
"Microsoft.NETCore.App",
"Microsoft.NETCore.Platforms"
};
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using dotnetCampus.SourceYard.Context;
using dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts;
namespace dotnetCampus.SourceYard.PackFlow.NuspecFiles
{
static class DependenciesParser
{
/// <summary>
/// 获取框架依赖内容
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static List<NuspecFrameworkAssembly>? GetFrameworkAssemblies(IPackingContext context)
{
var nuspecFrameworkAssemblies = new List<NuspecFrameworkAssembly>();
foreach (var targetFrameworkPackageInfo in context.MultiTargetingPackageInfo
.ValidTargetFrameworkPackageInfoList)
{
var sourcePackingFolder = targetFrameworkPackageInfo.SourcePackingFolder.FullName;
var frameworkReferenceVersionFile = Path.Combine(sourcePackingFolder, "FrameworkReferenceVersionFile.txt");
if (File.Exists(frameworkReferenceVersionFile))
{
foreach (var assembly in File.ReadAllLines(frameworkReferenceVersionFile).Where(t=>!string.IsNullOrWhiteSpace(t)))
{
nuspecFrameworkAssemblies.Add(new NuspecFrameworkAssembly()
{
TargetFramework = targetFrameworkPackageInfo.TargetFramework,
AssemblyName = assembly
});
}
}
}
if (nuspecFrameworkAssemblies.Count == 0)
{
// 如果没有任何框架依赖,那么应该啥都不输出
return null;
}
return nuspecFrameworkAssemblies;
}
/// <summary>
/// 获取依赖内容
/// </summary>
/// <returns></returns>
public static List<NuspecGroup> GetDependencies(IPackingContext context)
{
ILogger logger = context.Logger;
var nuspecGroups = new List<NuspecGroup>();
foreach (var targetFrameworkPackageInfo in context.MultiTargetingPackageInfo.ValidTargetFrameworkPackageInfoList)
{
var sourcePackingFolder = targetFrameworkPackageInfo.SourcePackingFolder.FullName;
var packageReferenceVersionFile = Path.Combine(sourcePackingFolder, "PackageReferenceVersionFile.txt");
var buildProps = context.BuildProps;
var dependencies = GetDependencies(packageReferenceVersionFile, buildProps.SourceYardPackageReferenceList,
buildProps.SourceYardExcludePackageReferenceList,logger);
nuspecGroups.Add(new NuspecGroup()
{
TargetFramework = targetFrameworkPackageInfo.TargetFramework,
Dependencies = dependencies
});
}
return nuspecGroups;
}
/// <summary>
/// 获取依赖
/// </summary>
/// <param name="contextPackageVersion">引用的NuGet包于版本号</param>
/// <param name="sourceYardPackageReferenceList">源代码包</param>
/// <param name="excludePackageReferenceList">排除的依赖</param>
/// <param name="logger"></param>
/// <returns></returns>
private static List<NuspecDependency> GetDependencies(string contextPackageVersion,
List<string> sourceYardPackageReferenceList, List<string> excludePackageReferenceList, ILogger logger)
{
var nuspecDependencyList = ParserPackageVersion(contextPackageVersion, sourceYardPackageReferenceList, logger);
// 如果在排除列表就移除
if (excludePackageReferenceList.Count > 0)
{
var excludeList = new HashSet<string>(excludePackageReferenceList);
nuspecDependencyList.RemoveAll(temp => excludeList.Contains(temp.Id));
}
return nuspecDependencyList;
}
private static List<NuspecDependency> ParserPackageVersion(string packageVersionFile,
List<string> sourceYardPackageReferenceList, ILogger logger)
{
// 包含在 sdk 的库,这些库不应该加入引用
string[] frameworkSDKNugetList = new[]
{
"Microsoft.NETCore.App",
"Microsoft.NETCore.Platforms"
};
var nuspecDependencyList = new List<NuspecDependency>();
var packageVersionRegex = new Regex(@"Name='(\S+)' Version='([\S|\-]+)' PrivateAssets='(\S*)'");
using (var stream = File.OpenText(packageVersionFile))
{
string? line;
while ((line = stream.ReadLine()) != null)
{
var match = packageVersionRegex.Match(line);
if (match.Success)
{
var name = match.Groups[1].Value;
var version = match.Groups[2].Value;
var privateAssets = match.Groups[3].Value;
// 在源代码包如果项目引用的是 private asset 的库,那么就不应该添加引用
// 因为源代码是没有框架的依赖,对 sdk 带的库也不添加
var isPrivateAssetsAll = privateAssets.IndexOf("all", StringComparison.OrdinalIgnoreCase) >= 0;
// net45 没有下面方法
//var isPrivateAssetsAll = privateAssets.Contains("all", comparer);
// 解决 https://github.com/dotnet-campus/SourceYard/issues/60
// 即使有某个包标记了使用 private asset 是 All 的,但是这个包是一个源代码包,那么打包的时候就需要添加他的引用依赖
var includeInSourceYardPackageReference =
sourceYardPackageReferenceList.Any(temp =>
temp.Equals(name, StringComparison.OrdinalIgnoreCase));
if ((!isPrivateAssetsAll || includeInSourceYardPackageReference)
&& !frameworkSDKNugetList.Contains(name))
{
nuspecDependencyList.Add(new NuspecDependency()
{
Id = name,
Version = version
});
}
}
else
{
logger.Warning($"项目所引用的 NuGet 包包含有无法识别的格式,包信息:{line}");
}
}
}
return nuspecDependencyList;
}
}
}
\ No newline at end of file
using System.Xml.Serialization;
namespace dotnetCampus.SourceYard.PackFlow.Nuspec
namespace dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts
{
public class NuspecDependency
{
......
using System.Xml.Serialization;
namespace dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts
{
public class NuspecFrameworkAssembly
{
[XmlAttribute("assemblyName", Namespace = "")]
public string AssemblyName { get; set; } = null!;
[XmlAttribute("targetFramework")]
public string TargetFramework { get; set; } = null!;
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Xml.Serialization;
namespace dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts
{
public class NuspecGroup
{
[XmlAttribute("targetFramework", Namespace = "")]
public string TargetFramework { get; set; } = null!;
[XmlElement(elementName: "dependency")]
public List<NuspecDependency> Dependencies { set; get; } = new List<NuspecDependency>();
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Reflection;
using System.Xml.Serialization;
namespace dotnetCampus.SourceYard.PackFlow.Nuspec
namespace dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts
{
[Serializable]
[XmlType(typeName: "metadata", Namespace = "")]
......@@ -21,8 +21,12 @@ namespace dotnetCampus.SourceYard.PackFlow.Nuspec
public string? Description { set; get; }
[XmlArray(elementName: "dependencies", Namespace = "")]
[XmlArrayItem(elementName: "dependency")]
public List<NuspecDependency> Dependencies { set; get; } = new List<NuspecDependency>();
[XmlArrayItem(elementName: "group")]
public List<NuspecGroup> Dependencies { set; get; } = new List<NuspecGroup>();
[XmlArray(elementName: "frameworkAssemblies", Namespace = "")]
[XmlArrayItem(elementName: "frameworkAssembly")]
public List<NuspecFrameworkAssembly>? FrameworkAssemblies { set; get; }
[XmlElement("id")]
public string? Id { get; set; }
......@@ -118,6 +122,8 @@ namespace dotnetCampus.SourceYard.PackFlow.Nuspec
/// <summary>
/// 通过这个属性可以在安装源代码包的时候默认选 private assets 这样就可以让安装源代码包的项目被引用的时候,引用的项目不需要再安装源代码包
/// </summary>
/// 设置DevelopmentDependency时,不单会设置PrivateAssets为all,同时也会将IncludeAssets设置为runtime; build; native; contentfiles; analyzers; buildtransitive,这会导致不会自动去加载源码包使用的其他nuget库
/// https://github.com/dotnet-campus/SourceYard/issues/112
[XmlElement("developmentDependency")]
public string? DevelopmentDependency { get; set; } = "true";
......
using System.Xml.Serialization;
namespace dotnetCampus.SourceYard.PackFlow.Nuspec
namespace dotnetCampus.SourceYard.PackFlow.NuspecFiles.NuspecContexts
{
[XmlType("package")]
public class NuspecPackage
......
......@@ -15,19 +15,14 @@ namespace dotnetCampus.SourceYard
string intermediateDirectory,
string packageOutputPath,
string packageVersion,
string? compileFile,
string? resourceFile,
string? contentFile,
string? page,
string? applicationDefinition,
string? noneFile,
string? embeddedResource,
BuildProps buildProps,
string? packageId,
string? packageReferenceVersion
BuildProps buildProps,
DirectoryInfo commonSourcePackingFolder,
MultiTargetingPackageInfo multiTargetingPackageInfo,
Logger logger
)
{
Logger = new Logger();
Logger = logger;
Logger.Message(message: "初始化打包");
......@@ -60,20 +55,21 @@ namespace dotnetCampus.SourceYard
_intermediateDirectory = Path.GetFullPath(path: intermediateDirectory);
_packageOutputPath = Path.GetFullPath(path: packageOutputPath);
_packageVersion = packageVersion;
_packageReferenceVersion = Path.GetFullPath(path: packageReferenceVersion);
_multiTargetingPackageInfo = multiTargetingPackageInfo;
BuildProps = buildProps;
PackageId = packageId;
PackagedProjectFile = new PackagedProjectFile
(
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),
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
);
......@@ -114,15 +110,8 @@ namespace dotnetCampus.SourceYard
return;
}
//Directory.Build.props
var buildProps = BuildProps;
if (string.IsNullOrWhiteSpace(projectName))
{
Logger.Error($"无法从 {projectFile} 解析出正确的项目名称。");
return;
}
IPackFlow? current = null;
try
{
......@@ -139,7 +128,7 @@ namespace dotnetCampus.SourceYard
_packageOutputPath,
packingFolder,
PackagedProjectFile,
_packageReferenceVersion
_multiTargetingPackageInfo
)
{
BuildProps = buildProps,
......@@ -171,17 +160,13 @@ namespace dotnetCampus.SourceYard
private readonly string _packageOutputPath = null!;
private readonly string _packageVersion = null!;
private readonly string _packageReferenceVersion = null!;
private readonly MultiTargetingPackageInfo _multiTargetingPackageInfo;
private readonly IPackFlow[] _packers = null!;
private PackagedProjectFile PackagedProjectFile { get; } = null!;
private BuildProps BuildProps { get; } = null!;
private static string GetFile(string? file)
{
return string.IsNullOrWhiteSpace(file) ? "" : Path.GetFullPath(file);
}
/// <summary>
/// 准备一个空白的文件夹用来放文件
/// </summary>
......
......@@ -5,6 +5,7 @@ using System.Linq;
using dotnetCampus.Cli;
using dotnetCampus.Cli.Standard;
using dotnetCampus.SourceYard.Cli;
using dotnetCampus.SourceYard.Context;
using dotnetCampus.SourceYard.Utils;
namespace dotnetCampus.SourceYard
......@@ -20,20 +21,51 @@ namespace dotnetCampus.SourceYard
.Run();
}
/// <summary>
/// 更改命令行传入内容,用于方便接入后续步骤
/// </summary>
/// <param name="args"></param>
private static void MagicTransformMultiTargetingToFirstTarget(string[] args)
{
var argDict = dotnetCampus.Cli.CommandLine.Parse(args).ToDictionary(
x => x.Key,
x => x.Value?.FirstOrDefault()?.Trim());
var targetFrameworks = argDict["TargetFrameworks"];
if (targetFrameworks != null && !string.IsNullOrWhiteSpace(argDict["TargetFrameworks"]))
if (targetFrameworks != null && !string.IsNullOrWhiteSpace(targetFrameworks))
{
var first = targetFrameworks.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
if (!string.IsNullOrWhiteSpace(first))
// 这里必须考虑如下情况
/*
* <TargetFrameworks>netcoreapp3.1;net45;net6.0</TargetFrameworks>
*
* <PackageReference Include="dotnetCampus.SourceYard" Version="0.1.19393-alpha10" Condition="'$(TargetFramework)'=='net45'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
*/
// 为什么只有 net45 才安装?原因是只有单个框架打包才有此需求
// 此时就不合适获取首个,而是应该获取有带打包的
string? firstTargetFramework = null;
var multiTargetingPackageInfoFolder = argDict["MultiTargetingPackageInfoFolder"];
if (multiTargetingPackageInfoFolder != null && !string.IsNullOrEmpty(multiTargetingPackageInfoFolder) &&
Directory.Exists(multiTargetingPackageInfoFolder))
{
var multiTargetingPackageInfo =
new MultiTargetingPackageInfo(new DirectoryInfo(multiTargetingPackageInfoFolder),
targetFrameworks);
firstTargetFramework = multiTargetingPackageInfo.ValidTargetFrameworkPackageInfoList.FirstOrDefault()?.TargetFramework;
}
if(string.IsNullOrEmpty(firstTargetFramework))
{
firstTargetFramework = targetFrameworks.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
}
if (!string.IsNullOrWhiteSpace(firstTargetFramework))
{
for (int i = 0; i < args.Length; i++)
{
args[i] = args[i].Replace("\\SourcePacking\\", $"\\{first}\\SourcePacking\\");
args[i] = args[i].Replace("\\SourcePacking\\", $"\\{firstTargetFramework}\\SourcePacking\\");
}
}
}
......@@ -47,24 +79,31 @@ namespace dotnetCampus.SourceYard
#endif
var logger = new Logger();
FixOptions(options);
try
{
logger.Message("开始打源码包");
logger.Message("Source packaging");
var projectFile = options.ProjectFile;
var intermediateDirectory = options.IntermediateDirectory;
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}");
// 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);
......@@ -86,22 +125,32 @@ SourcePackingDirectory: {options.SourcePackingDirectory}");
PackageTags = options.PackageTags
};
buildProps.SetSourcePackingDirectory(Path.GetFullPath(options.SourcePackingDirectory));
buildProps.SetSourcePackingDirectory(sourcePackingFolder.FullName);
new Packer(projectFile: projectFile,
var packer = 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,
// 不再从 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,
packageReferenceVersion: options.PackageReferenceVersion).Pack();
commonSourcePackingFolder: sourcePackingFolder,
multiTargetingPackageInfo: multiTargetingPackageInfo,
// 多框架下,每个框架有自己的引用路径
//packageReferenceVersion: options.PackageReferenceVersion
logger: logger
);
packer.Pack();
}
catch (Exception e)
{
......@@ -131,5 +180,72 @@ SourcePackingDirectory: {options.SourcePackingDirectory}");
return "";
}
}
/// <summary>
/// 兼容修复
/// </summary>
/// <param name="options"></param>
private static void FixOptions(Options options)
{
if (string.IsNullOrWhiteSpace(options.MultiTargetingPackageInfoFolder))
{
// 如果多框架是空的字符串或者是空的,为了后续的判断方便,统一设置为空值
options.MultiTargetingPackageInfoFolder = null!;
}
}
/// <summary>
/// 获取通用的 SourcePacking 文件夹,无视框架版本的不同
/// </summary>
/// <returns></returns>
private static DirectoryInfo GetCommonSourcePackingFolder(MultiTargetingPackageInfo multiTargetingPackageInfo, Logger logger)
{
// 获取时,需要判断文件夹是否合法
var fileList = multiTargetingPackageInfo.ValidTargetFrameworkPackageInfoList;
if (fileList.Count == 0)
{
logger.Error($"Can not find any TargetFramework info file from \"{multiTargetingPackageInfo.MultiTargetingPackageInfoFolder.FullName}\"");
Exit(-1);
}
// 如果是单个框架的项目,那么返回即可
if (fileList.Count == 1)
{
return fileList[0].SourcePackingFolder;
}
else
{
return fileList[0].SourcePackingFolder;
}
}
private static string GetIntermediateDirectory(MultiTargetingPackageInfo multiTargetingPackageInfo, Options options, Logger logger)
{
// 多框架和单个框架的逻辑不相同
var folder = options.MultiTargetingPackageInfoFolder;
folder = Path.GetFullPath(folder);
const string packageName = "Package";
if (string.IsNullOrWhiteSpace(options.TargetFrameworks))
{
// 单个框架的项目
var sourcePackingFolder = GetCommonSourcePackingFolder(multiTargetingPackageInfo, logger);
// 预期是输出 obj\Debug\SourcePacking\Package 文件
var intermediateFolder = Path.Combine(sourcePackingFolder.FullName, packageName);
return intermediateFolder;
}
else
{
// 多个框架的项目
// 输出 obj\Debug\SourceYardMultiTargetingPackageInfoFolder\Package 文件夹
return Path.Combine(folder, packageName);
}
}
private static void Exit(int code)
{
Environment.Exit(code);
}
}
}
......@@ -13,6 +13,11 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NoPackageAnalysis>true</NoPackageAnalysis>
<DevelopmentDependency>true</DevelopmentDependency>
<!-- 设置支持的运行时版本,当前 dotnet core 设置为 2.0 是古老的版本,需要通过如下配置让只安装新版本的设备可以运行 -->
<!-- [选择要使用哪个 .NET 版本](https://docs.microsoft.com/zh-cn/dotnet/core/versions/selection) -->
<!-- 如果缺少所请求的主要版本,则前滚到下一个可用的更高主要版本和最低的次要版本 -->
<RollForward>Major</RollForward>
<!-- 因为只把主软件复制过去,依赖的库没有复制,所以不使用这个方法 -->
<!-- 在下面可以看到使用的是复制整个文件夹 -->
......@@ -34,7 +39,7 @@
<PackageReference Include="dotnetCampus.CommandLine.Source" Version="3.3.0" PrivateAssets="All" />
<PackageReference Include="dotnetCampus.Configurations.Source" Version="1.6.9" PrivateAssets="All" />
<PackageReference Include="Walterlv.NullableAttributes.Source" Version="6.0.0" PrivateAssets="All" />
<PackageReference Include="dotnetCampus.MSBuildUtils.Source" Version="1.1.0">
<PackageReference Include="dotnetCampus.MSBuildUtils.Source" Version="1.1.1-alpha01">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册