Skip to content

Commit b60d3f5

Browse files
authored
Merge pull request #156 from dotnet-campus/t/shs/versionfolder
打包时支持配置使用 版本号文件夹 替换 bin文件夹;支持添加 X-Package-System 字段
2 parents c0a1d74 + 1410fba commit b60d3f5

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

DebUOS/Packaging.DebUOS.NuGet/Build/package.targets

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(DebControlDepends)))"/>
155155
<DebUOSPackingWriteArgLine Include=">"/>
156156

157+
<DebUOSPackingWriteArgLine Include=">"/>
158+
<DebUOSPackingWriteArgLine Include="DebControlXPackageSystem" Condition="$(DebControlXPackageSystem)!=''"/>
159+
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(DebControlXPackageSystem)))"/>
160+
<DebUOSPackingWriteArgLine Include=">"/>
161+
157162
<DebUOSPackingWriteArgLine Include=">"/>
158163
<DebUOSPackingWriteArgLine Include="AppName" Condition="$(AppName)!=''"/>
159164
<DebUOSPackingWriteArgLine Include="$(AppName)"/>
@@ -229,6 +234,11 @@
229234
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(DesktopMimeType)))"/>
230235
<DebUOSPackingWriteArgLine Include=">"/>
231236

237+
<DebUOSPackingWriteArgLine Include=">"/>
238+
<DebUOSPackingWriteArgLine Include="CopyDesktopFileToUsrShareApplications" Condition="$(CopyDesktopFileToUsrShareApplications)!=''"/>
239+
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(CopyDesktopFileToUsrShareApplications)))"/>
240+
<DebUOSPackingWriteArgLine Include=">"/>
241+
232242
<DebUOSPackingWriteArgLine Include=">"/>
233243
<DebUOSPackingWriteArgLine Include="PackingFolder" Condition="$(PackingFolder)!=''"/>
234244
<DebUOSPackingWriteArgLine Include="$(PackingFolder)"/>
@@ -294,6 +304,11 @@
294304
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(ExcludePackingDebFileExtensions)))"/>
295305
<DebUOSPackingWriteArgLine Include=">"/>
296306

307+
<DebUOSPackingWriteArgLine Include=">"/>
308+
<DebUOSPackingWriteArgLine Include="UsingAppVersionInsteadOfBinOnDebPacking" Condition="$(UsingAppVersionInsteadOfBinOnDebPacking)!=''"/>
309+
<DebUOSPackingWriteArgLine Include="$([MSBuild]::Escape($(UsingAppVersionInsteadOfBinOnDebPacking)))"/>
310+
<DebUOSPackingWriteArgLine Include=">"/>
311+
297312
</ItemGroup>
298313
<WriteLinesToFile File="$(DebUOSPackingArgsFile)" Lines="@(DebUOSPackingWriteArgLine)" Overwrite="True" />
299314
<Exec Command="dotnet &quot;$(MSBuildThisFileDirectory)..\tools\Packaging.DebUOS.Tool.dll&quot; -p $(DebUOSPackingArgsFile)" />

DebUOS/Packaging.DebUOS/Contexts/Configurations/DebUOSConfiguration.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ public string? DebControlDepends
316316
set => SetValue(value);
317317
get => GetString();
318318
}
319+
320+
/// <summary>
321+
/// 此字段若配置了,则会在 control 文件中写入 X-Package-System 属性,值为此字段的值
322+
/// </summary>
323+
public string? DebControlXPackageSystem
324+
{
325+
set => SetValue(value);
326+
get => GetString();
327+
}
319328

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

676+
/// <summary>
677+
/// 打包时是否将 bin 文件夹替换为应用版本号,默认不替换。如设置为 True 将使用 <see cref="UOSDebVersion"/> 属性的版本号作为文件夹名替换 bin 文件夹名
678+
/// </summary>
679+
/// <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>
680+
/// <example>False</example>
681+
public bool UsingAppVersionInsteadOfBinOnDebPacking
682+
{
683+
set => SetValue(value);
684+
get => GetBoolean() ?? false;
685+
}
686+
667687
#endregion
668688
}

DebUOS/Packaging.DebUOS/DebUOSPackageFileStructCreator.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,20 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
9090
var appIdFolder = Path.Join(packingFolder, "opt", "apps", appId);
9191
var filesFolder = Path.Join(appIdFolder, "files");
9292
Directory.CreateDirectory(filesFolder);
93-
var applicationBin = Path.Join(filesFolder, "bin");
94-
if (!FolderUtils.CreateSymbolLinkOrCopyFolder(projectPublishFolder, applicationBin))
93+
var binaryFolderName = "bin";
94+
if (configuration.UsingAppVersionInsteadOfBinOnDebPacking)
9595
{
96-
throw new PackagingException($"将发布输出文件拷贝到安装包打包文件夹失败,从 '{projectPublishFolder}' 复制到 '{applicationBin}' 失败");
96+
// 如果配置了使用版本号作为文件夹名,则使用版本号作为文件夹名
97+
// 否则使用 bin 作为文件夹名
98+
binaryFolderName = configuration.UOSDebVersion;
9799
}
98100

101+
var applicationFolder = Path.Join(filesFolder, binaryFolderName);
102+
if (!FolderUtils.CreateSymbolLinkOrCopyFolder(projectPublishFolder, applicationFolder))
103+
{
104+
throw new PackagingException($"将发布输出文件拷贝到安装包打包文件夹失败,从 '{projectPublishFolder}' 复制到 '{applicationFolder}' 失败");
105+
}
106+
99107
// opt\apps\AppId\entries
100108
// opt\apps\AppId\entries\applications
101109
var entriesFolder = Path.Join(appIdFolder, "entries");
@@ -153,7 +161,7 @@ public void CreatePackagingFolder(DebUOSConfiguration configuration)
153161
{
154162
// 这里不能使用 Path.Join 方法,因为如果在 Windows 上进行打包,会将 \ 替换为 /,导致打包失败
155163
//var exec = Path.Join("/opt/apps", appId, "files", "bin", configuration.AssemblyName);
156-
var exec = $"/opt/apps/{appId}/files/bin/{configuration.AssemblyName}";
164+
var exec = $"/opt/apps/{appId}/files/{binaryFolderName}/{configuration.AssemblyName}";
157165
stringBuilder.Append($"Exec={exec}\n");
158166
}
159167

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

378+
if (!string.IsNullOrEmpty(configuration.DebControlXPackageSystem))
379+
{
380+
stringBuilder.Append($"X-Package-System: {configuration.DebControlXPackageSystem}\n");
381+
}
382+
370383
File.WriteAllText(controlFile, stringBuilder.ToString(), encoding);
371384
}
372385

0 commit comments

Comments
 (0)