找不到类型或名称空间&& quot;您是否缺少程序集引用&quot ;?虽然所有参考文献都是正确的 [英] Type or namespace not found "are you missing assembly reference" while all references are correct

查看:92
本文介绍了找不到类型或名称空间&& quot;您是否缺少程序集引用&quot ;?虽然所有参考文献都是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MSBuildWorkspace类.我的项目中有所有程序集引用.当我在对象浏览器中打开引用时,我会看到要使用的名称空间和类.但是在我下面的using语句中,

I am trying to use MSBuildWorkspace class . I have all assembly references in my project. When I open the reference in object browser, I see the namespace and the class I am trying to use. But in my following using statement,

使用Microsoft.CodeAnalysis.MSBuild

我得到

The type or namespace name 'MSBuild' does not exist in the namespace 'Microsoft.CodeAnalysis' (are you missing an assembly reference?)

可笑的是,语法突出显示器可以识别类型名称,编译器会抱怨

But funny that Syntax highlighter recognizes the type name, its the compiler complaining

这是构建日志

   1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3258: The primary reference "Microsoft.CodeAnalysis.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
    1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3258: The primary reference "Microsoft.CodeAnalysis.VisualBasic.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
    1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3258: The primary reference "Microsoft.CodeAnalysis.CSharp.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
    1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3258: The primary reference "Microsoft.CodeAnalysis.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
    1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3258: The primary reference "Microsoft.CodeAnalysis.VisualBasic.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
    1>c:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3258: The primary reference "Microsoft.CodeAnalysis.CSharp.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
    1>c:\users\fahadash\documents\visual studio 2012\Projects\RoslynEditor\RoslynEditor\MainWindow.xaml.cs(37,36,37,43): error CS0234: The type or namespace name 'MSBuild' does not exist in the namespace 'Microsoft.CodeAnalysis' (are you missing an assembly reference?)
    1>c:\users\fahadash\documents\visual studio 2012\Projects\RoslynEditor\RoslynEditor\MainWindow.xaml.cs(37,96,37,103): error CS0234: The type or namespace name 'MSBuild' does not exist in the namespace 'Microsoft.CodeAnalysis' (are you missing an assembly reference?)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

推荐答案

因此,

警告MSB3258:无法解析主引用"Microsoft.CodeAnalysis.Workspaces",因为它间接依赖于.NET Framework程序集"Microsoft.Build,版本= 12.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a",其版本"12.0.0.0"比当前目标框架中的版本"4.0.0.0"更高.
warning MSB3258: The primary reference "Microsoft.CodeAnalysis.Workspaces" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.

意味着您正在与针对.NET 4.0框架的项目一起构建.您应该将Visual Studio 2013定位为4.5.1.不支持其他配置.我不建议尝试通过使警告消失来强制"执行此操作,否则可能会导致问题.Roslyn使用4.5中添加的API,因此您在尝试使问题保持​​沉默时会遇到麻烦.

Means you are building with your project targeting the .NET 4.0 framework. You should be targeting 4.5.1 with Visual Studio 2013. Other configurations are unsupported. I do not recommend trying to "force" this by silencing the warning -- that can just cause issues down the road. Roslyn uses APIs added in 4.5, so you will have troubles trying to silence the issue.

这篇关于找不到类型或名称空间&& quot;您是否缺少程序集引用&quot ;?虽然所有参考文献都是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆