当 SingleFile 为 true 时,SQLite 在连接打开期间抛出异常

问题描述 投票:0回答:1

我试图将我的应用程序打包在一个文件中,但我不断收到此异常,导致我的 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# visual-studio sqlite .net-core asp.net-core-6.0
1个回答
0
投票

据报道here,我将其添加到 .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 捆绑的方式不会导致其他问题。

© www.soinside.com 2019 - 2024. All rights reserved.