Я пытаюсь упаковать свое приложение в один файл, но постоянно получаю исключение, которое убивает мой exe:
Value cannot be null. (Parameter 'path1')
System.Private.CoreLib
at System.IO.Path.Combine(String path1, String path2)
at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
at System.Data.SQLite.SQLiteConnection..ctor(String connectionString)
at OrderManager.Program.Main() in C:\Users\Documents\GitHub\OrderManager\Program.cs:line 52
В этом нет ничего особенного:
51. File.AppendAllText(AppContext.BaseDirectory + @"\log.txt", ProgramParameters.connectionStringAdmin + Environment.NewLine);
52. connection = new(ProgramParameters.connectionStringAdmin);
Я проверяю содержание ProgramParameters.connectionStringAdmin
, оно правильное:
Data Source = C:\Users\Documents\GitHub\OrderManager\bin\Release\net6.0-windows10.0.22621.0\publish\db\ManagerOrdini.db ; cache=shared; synchronous = NORMAL ; journal_mode=WAL; temp_store = memory; mmap_size = 30000000000;
Режимы Debug
и Release
работают как положено, без ошибок.
Моя проба, помимо некоторого тестирования кода, заключалась в исключении пакета из файла .csproj, но, видимо, это не распространяется на пакеты:
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
<OutputType>WinExe</OutputType>
<EmbedInteropTypes>True</EmbedInteropTypes>
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>
<CustomResourceTypesSupport>true</CustomResourceTypesSupport>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<IsWebBootstrapper>false</IsWebBootstrapper>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<DebuggerSupport>true</DebuggerSupport>
<DebugType>embedded</DebugType>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
...
<ItemGroup>
<PackageReference Include = "System.Data.SQLite" Version = "1.0.118">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</PackageReference>
...
Есть еще предложения?
🤔 А знаете ли вы, что...
C# поддерживает атрибуты, которые позволяют добавлять метаданные к коду.
Как сообщалось здесь, я добавил это в конец файла .csproj:
<Target Name = "ExplicitRemoveFromFilesToBundle" BeforeTargets = "GenerateSingleFileBundle" DependsOnTargets = "PrepareForBundle">
<ItemGroup>
<FilesToRemoveFromBundle Include = "@(FilesToBundle)" Condition = "$([System.String]::new('%(Filename)').ToLower().EndsWith('data.sqlite'))" />
</ItemGroup>
<Message Text = "FilesToRemoveFromBundle '@(FilesToRemoveFromBundle)'" Importance = "high" />
<ItemGroup>
<FilesToBundle Remove = "@(FilesToRemoveFromBundle)" />
</ItemGroup>
</Target>
<Target Name = "CopyFilesToRemoveFromBundle" AfterTargets = "Publish">
<Copy SourceFiles = "@(FilesToRemoveFromBundle)" DestinationFolder = "$(PublishDir)" />
<Message Text = "Copied files to remove from bundle to '$(PublishDir)'" Importance = "high" />
</Target>
Надеюсь, что использование пакетов VS не приведет к другим проблемам.