无法在Windows Server 2003中使用Windows 8.1/Visual Studio 2013构建的程序中加载程序集

问题描述:

我有一个程序可以在我的开发PC上运行,但不是在我想运行它的服务器上运行。当我在服务器上运行的程序中,我得到这个错误:无法在Windows Server 2003中使用Windows 8.1/Visual Studio 2013构建的程序中加载程序集

Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

我的开发PC是Windows 8.1与Visual Studio 2013和SQL Server 2012开发工具。服务器是运行.NET 4的Windows Server 2003 R2 Standard Edition Service Pack 2。

我首先尝试将服务器找不到的每个程序集的Copy Local设置为true。然后,我终于在我的程序中没有明确引用的程序集中出现错误,所以我想我可能会以错误的方式解决这个问题。

Message: Could not load file or assembly 'Microsoft.SqlServer.SqlClrProvider, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. StackTrace:
at Microsoft.SqlServer.Management.Common.ConnectionManager.CallerHavePermissionToUseSQLCLR() at Microsoft.SqlServer.Management.Common.ConnectionManager..ctor(SqlConnection sqlConnectionObject) at Microsoft.SqlServer.Management.Common.ServerConnection..ctor(SqlConnection sqlConnection)

我用我在程序的组件可以从Microsoft SQL Server 2012 Feature Pack安装好,但这些2012包不与Windows Server 2003兼容的最新组件,我设法安装赢Server 2003上得到来自Microsoft SQL Server 2008 R2 Feature Pack,这让我到服务器上的程序集版本10。当我尝试我的Windows 8.1开发PC上安装这些,我得到这个错误:

Installation of Microsoft SQL Server 2008 R2 Management Objects failed because a higher version already exists on the machine. To proceed, uninstall the higher version and then run Microsoft SQL Server 2008 R2 Management Objects Setup again.

我不喜欢的倒退从2012年到我的开发机器上2008和组件的想法,我必须支持SQL Server 2005和2012.有什么方法可以告诉Visual Studio 2013将这些较旧的汇编版本作为目标?

改变程序集版本是我需要做的。您可以在Visual Studio中指定不同的汇编版本,方法是创建一个app.config文件并添加如下内容:

<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.SqlServer.ConnectionInfo" 
          publicKeyToken="89845dcd8080cc91" /> 
     <bindingRedirect oldVersion="11.0.0.0" 
         newVersion="10.0.0.0"/> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration>