2017-09-26 303 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

相關問題