Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果我同时需要32位和64位,如何添加对类库的引用_C#_Visual Studio 2010 - Fatal编程技术网

C# 如果我同时需要32位和64位,如何添加对类库的引用

C# 如果我同时需要32位和64位,如何添加对类库的引用,c#,visual-studio-2010,C#,Visual Studio 2010,在我的项目中,我使用两种配置—32位和64位(因为我在32位机器上开发,但部署到64位机器) 我的项目包含类库,位于“C:…\Commons\bin\Debug\Commons.dll”。我已将此dll添加到引用中,但当我切换到64位时,这当然不起作用 所以我需要添加“特定于平台的引用”的机制 我知道我可以手工编辑.csproj文件来添加如下内容: <Reference Include="Commons" Condition="$(Platform) == 'x64'"> <

在我的项目中,我使用两种配置—32位和64位(因为我在32位机器上开发,但部署到64位机器)

我的项目包含类库,位于“C:…\Commons\bin\Debug\Commons.dll”。我已将此dll添加到引用中,但当我切换到64位时,这当然不起作用

所以我需要添加“特定于平台的引用”的机制

我知道我可以手工编辑.csproj文件来添加如下内容:

<Reference Include="Commons" Condition="$(Platform) == 'x64'">
  <HintPath>..\Commons\bin\x64\Release\Commons.dll</HintPath>
</Reference>
<Reference Include="Commons" Condition="$(Platform) == 'x86'">
  <HintPath>..\Commons\bin\x86\Release\Commons.dll</HintPath>
</Reference>

..\Commons\bin\x64\Release\Commons.dll
..\Commons\bin\x86\Release\Commons.dll
我应该为类库做同样的事情吗

我只是想知道,即使对于类库,VS也不支持“依赖于平台的引用”机制


upd似乎我实际上需要以某种方式链接4种类型的dll-x86/Debug、x86/Release、x64/Debug、x64/Release

事实上你不应该这样做。必须将代码编译为MSIL,并添加对DLL的MSIL版本的引用。您的代码和引用的代码将在运行时由运行时编译。如果它在x86计算机上工作,那么它将被编译为x86,在x64计算机上,它将被编译为x64。你不必为此担心


如果您认为JIT很慢,并且需要性能,您可以在目标计算机上更新程序集。

以下问题有解决方案。希望这有帮助。

对于部署,您可以编写清单或使用程序集类手动加载x86/x64 DLL。在运行时检测x86/x64是一个简单的sizeof(IntPtr)==4或8。在这方面也有类似的问题。我认为,您使用.csproj所做的事情是可以的。您真的需要有单独版本的程序集吗?您不能简单地将目标设置为anycpu吗?@Steve B,是的,我可以,否则某些DLL将不会加载是的,我同意Viktor的观点,您对.csproj文件的更改很好。显然您正在构建引用的程序集,为什么不将它们全部放在同一个解决方案中呢?使用项目引用而不是路径引用。然后,您可以为所需的任何目标组合选择正确的配置。