4

刚刚通过 Nuget 将我的 SQLite dll 更新到 v1.0.81.0,我收到如下错误。这发生在第一次成功执行一次或多次之后(不确定)。环境是 x64 机器上的 vs2010,但构建设置针对 x86。

我使用 SQLite 对我的 NHibernate 映射进行单元测试。过去经常发现 SQLite 有点“古怪”,我不愿意弄乱工作单元测试夹具(见下文)

有人知道这里出了什么问题吗?

干杯,
贝里尔

错误信息

Unable to copy file "...\x86\SQLite.Interop.dll" to "bin\Debug\x86\SQLite.Interop.dll". The process cannot access the file 'bin\Debug\x86\SQLite.Interop.dll' because it is being used by another process. Parties.Data.Impl.NHib.Tests

单元测试夹具(无论如何都足以显示文件访问)

public abstract class SQLiteTestFixture
{

    protected override void BeforeAllTests()
    {
        _configureDbFile();
        base.BeforeAllTests();
    }

    protected override void AfterAllTests()
    {
        base.AfterAllTests();

        _deleteAllDbFiles();
    }

    #region Db File Maintenance

    /// <summary>
    /// Using a file is likely slower than just memory but not noticeably so far,
    /// AND seems to be a bit more stable
    /// </summary>
    private const string DB_FILE_SUFFIX = ".Test.db";

    /// <summary>
    /// Just make some random file name with a known suffix, so we can clean up when done.
    /// </summary>
    private void _configureDbFile()
    {
        _dbFile = Path.GetFullPath(Guid.NewGuid().ToString("N") + DB_FILE_SUFFIX);

        // highly unlikely but just in case the same file is already out there
        _deleteDbFile();
    }

    private void _deleteDbFile()
    {
        if (File.Exists(_dbFile)) File.Delete(_dbFile);
    }

    private static void _deleteAllDbFiles()
    {
        var files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*" + DB_FILE_SUFFIX);
        foreach (var file in files)
        {
            File.Delete(file);
        }
    }

    private string _dbFile;

    #endregion

}

}

4

3 回答 3

2

我在使用 VS2010 和 TestDriven.Net 的 SQLite 1.0.88.0 时遇到了这个问题。我尝试了几个 SO 问题的答案,但唯一对我有用的是:

  1. 工具 -> 选项 -> TestDriven.Net -> 常规
  2. Run Test(s)下,取消选中“Cache tests process between test runs”
  3. 重新启动 Visual Studio

您现在应该能够运行测试、调试测试、重建等,而无需重新启动进程或 Visual Studio。

于 2013-08-08T14:28:20.277 回答
1

描述一种可能原因的知识库文章

以下大部分内容暂时解决了问题

于 2012-08-20T17:48:41.410 回答
0

将 SQLLite dll“复制到输出目录”更改为“如果更新则复制”就可以了。(您可能需要在更改属性后重新启动 VS)

于 2014-10-09T12:52:30.640 回答