3

我有一个两个项目的 .NET 4.5 C# 解决方案,一个项目 (projectA) 是一个类库,它有 5 个引用的 .dll(非 COM)文件。这些文件是 32/64 位特定的,所以我的构建路径中有两个 include/ 文件夹(include/x86/ 和 include/x64/),每个文件夹中都有各自的 .dll 文件。.dll 在 32 位和 64 位版本之间的名称完全相同。另一个项目 (projectB) 是一个引用 projectA 的控制台应用程序。当我配置为调试(或发布,没关系)x64 模式并构建时,一切正常。它将所有 5 个 .dll 复制到 bin/x64/ 目录,程序按预期工作。但是,当我将配置切换到 x86 模式并构建时,五个 .dll 中只有两个被复制到 bin/x86/ 目录,并且程序显然无法运行。它抛出 FileNotFoundException 并抱怨程序集不是

如果我手动将丢失的 .dll 文件复制(或在构建后事件中使用 xcopy)到 bin/x86/ 文件夹,则程序可以工作。因此,该问题似乎与 Visual Studios (2012 Update 1) 在构建期间未正确复制文件有关。projectA 中的所有 5 个引用都设置为 Copy: Local,并且它们在 Visual Studio 的“属性”框中的路径对于 x86 和 x64 模式都是正确的。当我在 x86-64 模式下自行构建 projectA 时,所有 5 个 .dll 都被正确复制到正确的 bin/ 文件夹中。所以这个问题还必须处理引用projectA的projectB。

以下是 projectA.csproj 文件的摘录:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
   <PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
   <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<Reference Include="BaseCommon">
  <HintPath>include\$(Platform)\BaseCommon.dll</HintPath>
</Reference>
<Reference Include="BaseDataAccess">
  <HintPath>include\$(Platform)\BaseDataAccess.dll</HintPath>
</Reference>
<Reference Include="BaseError">
  <HintPath>include\$(Platform)\BaseError.dll</HintPath>
</Reference>
<Reference Include="BaseTof">
  <HintPath>include\$(Platform)\BaseTof.dll</HintPath>
</Reference>
<Reference Include="MassSpecDataReader">
  <HintPath>include\$(Platform)\MassSpecDataReader.dll</HintPath>
</Reference>
<Reference Include="System" />

关于这个问题的任何想法?我假设我可以执行 xcopy 命令,但这似乎不是必需的,特别是如果它在 x64 模式下正确工作。

在三台不同的计算机上使用 windows 8 和 windows 7 64 位进行了测试。

4

1 回答 1

1

在意识到某些 .dll 文件是错误的版本后,我解决了这个问题。我在 .dll 上使用了 il​​dasm.exe,打开清单,并意识到某些 .dll 引用了其他 .dll 文件的错误版本。所以 msbuild 没有按预期执行二进制文件的副本。当我手动复制丢失的 .dll 文件时代码工作的原因是 API 在两个版本之间没有变化。

于 2013-02-10T21:03:08.057 回答