2017-09-26 286 views
0

使用System.ServiceModel的.NET Framework 2.0中的项目不能在Windows 7计算机上编译,而是在Windows Server 2008 R2计算机上编译。你能解释为什么吗?在Windows 7和Windows Server 2008 R2上使用.NET 2.0的System.ServiceModel

项目文件Test1.vbproj:

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 
    <PropertyGroup> 
    <OutputType>Library</OutputType> 
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> 
    <OutputPath>bin\Debug</OutputPath> 
    </PropertyGroup> 
    <ItemGroup> 
    <Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" /> 
    </ItemGroup> 
    <ItemGroup> 
    <Compile Include="IService1.vb" /> 
    </ItemGroup> 
    <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" /> 
</Project> 

的IService1.vb:

Imports System.ServiceModel 
<ServiceContract()> Public Interface IService1 
    <OperationContract()> Function Function1() As String 
End Interface 

在Windows 7 32位机这个项目不能编译,显示错误消息:

类型'OperationContract'未定义。
类型'ServiceContract'未定义。

在Windows Server 2008 R2 64位计算机上,此项目成功编译。

项目开盘的Windows 7计算机上:

enter image description here

该项目在Windows服务器上打开2008 R2机器:

enter image description here

的.NET框架安装在Windows 7机器:

enter image description here

安装了Windows Server 2008 R2的计算机上的.NET框架:

enter image description here

在Windows 7计算机上的Windows功能:

enter image description here

Windows功能在Windows Server 2008 R2机器:

enter image description here

Windows 7的机器性能:

enter image description here

在Windows Server 2008 R2机器性能:

enter image description here

是否有人有一个想法,为什么它不会对Windows 7的编译机器,但编译在Windows Server 2008 R2机器上?

我必须在Windows 7机器上编译它,而不必更改代码或项目文件。因此,我必须在Windows 7机器上安装或配置一些东西。

+0

是否在可选功能下安装了.net 3.5 sp1? – magicandre1981

+0

是的,在两台机器上都安装了.NET 3.5。我在问题中添加了相关的Windows功能屏幕截图。 – Alex

回答

0

在Windows注册表中,我指示.NET Framework 2.0也查找.NET Framework 3.0文件夹中的程序集。我把下面的代码放到一个名为DotNET3.0Compatiblity的文件中。reg:

Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx\.NET 3.0 Compatiblity] 
@="C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.0" 

我双击该文件,并创建了所需的注册表项。 您可以在下图中看到System.ServiceModel.dll现在位于文件夹C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll中。

Project Test1.vbproj compiles without errors

相关问题