Skip to content

Commit 1d9def8

Browse files
committed
修改配置文件存储目录,避免在单文件中执行出错
1 parent 8e3da67 commit 1d9def8

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/dotnet-cnblogs/Command/CommandSetConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public void Execute(CommandContext context)
3939
userName,
4040
Convert.ToBase64String(TeaHelper.Encrypt(Encoding.UTF8.GetBytes(pwd), context.EncryptKey)));
4141

42+
var path = Path.GetDirectoryName(context.AppConfigFilePath);
43+
if (!Directory.Exists(path))
44+
{
45+
Directory.CreateDirectory(path!);
46+
}
47+
4248
File.WriteAllText(context.AppConfigFilePath, JsonConvert.SerializeObject(config));
4349

4450
ConsoleHelper.PrintMsg("配置设置成功!");

src/dotnet-cnblogs/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ static void PrintTitle()
6666
static bool Init()
6767
{
6868
var context=new CommandContext();
69-
context.AppConfigFilePath = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location) ?? throw new InvalidOperationException(), CfgFileName);
69+
70+
var docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
71+
context.AppConfigFilePath = Path.Combine(docPath,"dotnet-cnblog", CfgFileName);
7072

7173
if (!File.Exists(context.AppConfigFilePath))
7274
{

src/dotnet-cnblogs/dotnet-cnblog.csproj

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Description>Cnblogs Article Quick Publish Tool.</Description>
1616
<Copyright>Copyright 2018-2020 stulzq</Copyright>
1717
<PackageProjectUrl>https://github.com/stulzq/dotnet-cnblogs-tool</PackageProjectUrl>
18-
<PackageLicenseUrl>https://github.com/stulzq/dotnet-cnblogs-tool/blob/master/LICENSE</PackageLicenseUrl>
18+
<PackageLicenseUrl></PackageLicenseUrl>
1919
<PackageTags>cnblogs</PackageTags>
2020
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2121
<Version>1.4.0</Version>
@@ -24,6 +24,20 @@
2424
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2525
<RootNamespace>Dotnetcnblog</RootNamespace>
2626
<PackageReleaseNotes>升级到 .NET 5.0 并且重构代码,使用方法有小的变更,请查看文档 https://github.com/stulzq/dotnet-cnblogs-tool</PackageReleaseNotes>
27+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
28+
</PropertyGroup>
29+
30+
<!-- 编译信息 -->
31+
<PropertyGroup Condition="'$(Configuration)'=='Release'">
32+
<!-- 单文件 -->
33+
<PublishSingleFile>true</PublishSingleFile>
34+
<!-- 预先部分AOT编译 -->
35+
<!--<PublishReadyToRun>true</PublishReadyToRun>-->
36+
<!-- 在主动剪裁模式下发布应用,在此模式下,将剪裁程序集中未使用的代码,并启用裁边器警告 -->
37+
<PublishTrimmed>true</PublishTrimmed>
38+
<IsTrimmable>true</IsTrimmable>
39+
<TrimMode>link</TrimMode>
40+
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
2741
</PropertyGroup>
2842

2943
<ItemGroup>
@@ -40,4 +54,12 @@
4054
</ItemGroup>
4155

4256

57+
<ItemGroup>
58+
<None Include="..\..\LICENSE">
59+
<Pack>True</Pack>
60+
<PackagePath></PackagePath>
61+
</None>
62+
</ItemGroup>
63+
64+
4365
</Project>

src/dotnet-cnblogs/publish.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true
2+
dotnet publish -r win-x86 -p:PublishSingleFile=true --self-contained true
3+
dotnet publish -r osx-x64 -p:PublishSingleFile=true --self-contained true
4+
dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true
5+
dotnet publish -r linux-arm -p:PublishSingleFile=true --self-contained true

0 commit comments

Comments
 (0)