Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打包时支持配置使用 版本号文件夹 替换 bin文件夹;支持添加 X-Package-System 字段 #156

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions DebUOS/Packaging.DebUOS.NuGet/Build/package.targets
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(DebControlDepends)))"/>
<DebUOSPackingWriteArgLine Include=">"/>

<DebUOSPackingWriteArgLine Include=">"/>
<DebUOSPackingWriteArgLine Include="DebControlXPackageSystem" Condition="$(DebControlXPackageSystem)!=''"/>
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(DebControlXPackageSystem)))"/>
<DebUOSPackingWriteArgLine Include=">"/>

<DebUOSPackingWriteArgLine Include=">"/>
<DebUOSPackingWriteArgLine Include="AppName" Condition="$(AppName)!=''"/>
<DebUOSPackingWriteArgLine Include="$(AppName)"/>
Expand Down Expand Up @@ -229,6 +234,11 @@
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(DesktopMimeType)))"/>
<DebUOSPackingWriteArgLine Include=">"/>

<DebUOSPackingWriteArgLine Include=">"/>
<DebUOSPackingWriteArgLine Include="CopyDesktopFileToUsrShareApplications" Condition="$(CopyDesktopFileToUsrShareApplications)!=''"/>
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(CopyDesktopFileToUsrShareApplications)))"/>
<DebUOSPackingWriteArgLine Include=">"/>

<DebUOSPackingWriteArgLine Include=">"/>
<DebUOSPackingWriteArgLine Include="PackingFolder" Condition="$(PackingFolder)!=''"/>
<DebUOSPackingWriteArgLine Include="$(PackingFolder)"/>
Expand Down Expand Up @@ -294,6 +304,11 @@
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(ExcludePackingDebFileExtensions)))"/>
<DebUOSPackingWriteArgLine Include=">"/>

<DebUOSPackingWriteArgLine Include=">"/>
<DebUOSPackingWriteArgLine Include="UsingAppVersionInsteadOfBinOnDebPacking" Condition="$(UsingAppVersionInsteadOfBinOnDebPacking)!=''"/>
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(UsingAppVersionInsteadOfBinOnDebPacking)))"/>
<DebUOSPackingWriteArgLine Include=">"/>

</ItemGroup>
<WriteLinesToFile File="$(DebUOSPackingArgsFile)" Lines="@(DebUOSPackingWriteArgLine)" Overwrite="True" />
<Exec Command="dotnet &quot;$(MSBuildThisFileDirectory)..\tools\Packaging.DebUOS.Tool.dll&quot; -p $(DebUOSPackingArgsFile)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ public string? DebControlDepends
set => SetValue(value);
get => GetString();
}

/// <summary>
/// 此字段若配置了,则会在 control 文件中写入 X-Package-System 属性,值为此字段的值
/// </summary>
public string? DebControlXPackageSystem
{
set => SetValue(value);
get => GetString();
}

/// <summary>
/// 应用名,英文名。将作为 opt\apps\${AppId}\entries\applications\${AppId}.desktop 和 opt\apps\${AppId}\info 的 Name 属性的值,不写默认和 AssemblyName 属性相同
Expand Down Expand Up @@ -664,5 +673,16 @@ public string? ExcludePackingDebFileExtensions
get => GetString() ?? ".pdb;.dbg;.md";
}

/// <summary>
/// 打包时是否将 bin 文件夹替换为应用版本号,默认不替换。如设置为 True 将使用 <see cref="UOSDebVersion"/> 属性的版本号作为文件夹名替换 bin 文件夹名
/// </summary>
/// <remarks>有些应用期望里层带版本号,即打出 `/opt/apps/${AppId}/files/${UOSDebVersion}/${AssemblyName}`格式的路径,如 `/opt/apps/com.dotnetcampus.app/files/1.0.0/app` 的路径,可以方便用来做软件更新。默认为 false 打出来的是 /opt/apps/${AppId}/files/bin/${AssemblyName} 格式的路径</remarks>
/// <example>False</example>
public bool UsingAppVersionInsteadOfBinOnDebPacking
{
set => SetValue(value);
get => GetBoolean() ?? false;
}

#endregion
}
21 changes: 17 additions & 4 deletions DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
var appIdFolder = Path.Join(packingFolder, "opt", "apps", appId);
var filesFolder = Path.Join(appIdFolder, "files");
Directory.CreateDirectory(filesFolder);
var applicationBin = Path.Join(filesFolder, "bin");
if (!FolderUtils.CreateSymbolLinkOrCopyFolder(projectPublishFolder, applicationBin))
var binaryFolderName = "bin";
if (configuration.UsingAppVersionInsteadOfBinOnDebPacking)
{
throw new PackagingException($"将发布输出文件拷贝到安装包打包文件夹失败,从 '{projectPublishFolder}' 复制到 '{applicationBin}' 失败");
// 如果配置了使用版本号作为文件夹名,则使用版本号作为文件夹名
// 否则使用 bin 作为文件夹名
binaryFolderName = configuration.UOSDebVersion;
}

var applicationFolder = Path.Join(filesFolder, binaryFolderName);
if (!FolderUtils.CreateSymbolLinkOrCopyFolder(projectPublishFolder, applicationFolder))
{
throw new PackagingException($"将发布输出文件拷贝到安装包打包文件夹失败,从 '{projectPublishFolder}' 复制到 '{applicationFolder}' 失败");
}

// opt\apps\AppId\entries
// opt\apps\AppId\entries\applications
var entriesFolder = Path.Join(appIdFolder, "entries");
Expand Down Expand Up @@ -153,7 +161,7 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
{
// 这里不能使用 Path.Join 方法,因为如果在 Windows 上进行打包,会将 \ 替换为 /,导致打包失败
//var exec = Path.Join("/opt/apps", appId, "files", "bin", configuration.AssemblyName);
var exec = $"/opt/apps/{appId}/files/bin/{configuration.AssemblyName}";
var exec = $"/opt/apps/{appId}/files/{binaryFolderName}/{configuration.AssemblyName}";
stringBuilder.Append($"Exec={exec}\n");
}

Expand Down Expand Up @@ -367,6 +375,11 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
stringBuilder.Append($"Depends: {configuration.DebControlDepends}\n");
}

if (!string.IsNullOrEmpty(configuration.DebControlXPackageSystem))
{
stringBuilder.Append($"X-Package-System: {configuration.DebControlXPackageSystem}\n");
}

File.WriteAllText(controlFile, stringBuilder.ToString(), encoding);
}

Expand Down
Loading