代码之家  ›  专栏  ›  技术社区  ›  Hellpless

错误CS0234:命名空间“Microsoft.Owin.Security”中不存在类型或命名空间名称“OAuth”(是否缺少程序集引用?)

  •  0
  • Hellpless  · 技术社区  · 6 年前

    我正在尝试使用cli构建一个项目:

    msbuild.exe project.sln
    

    App_Start\NinjectConfig.cs(3,31): error CS0234: The type or namespace name 'OAuth' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?) [path_to_file\file.csproj]
    

    我试过了 nuget restor 另外,我在项目文件夹的根目录中有一个包,您在其中有 packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45 具有 Microsoft.Owin.Security.OAuth.dll 文件。

    file.csproj

    <Reference Include="Microsoft.Owin.Security.OAuth">
    <HintPath>..\..\packages\Microsoft.Owin.Security.OAuth.2.1.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
    

    我可以看出版本的不同,但有两个问题: 2) 为什么nuget安装了错误的版本? 3) 如何从vs a config for nuget导出以安装所有软件包?

    0 回复  |  直到 6 年前
        1
  •  0
  •   Leo Liu    6 年前

    1) 为什么visual studio要在没有错误的情况下构建它?为什么它可以与vs一起使用,但不能与cli一起使用?

    由于我们没有您的项目/解决方案,因此无法找出Visual Studio生成时没有错误的原因。但如果你解决了后两个问题,你就不会对这个问题感到困惑。

    2) 为什么nuget安装了错误的版本?

    当您使用 nuget restore 命令行。这个命令行只是 下载并安装“软件包”文件夹中丢失的任何软件包 ,因此它不会更改 file.csproj 当您使用该命令行时,它只需下载包 Microsoft.Owin.Security.OAuth.3.0.1 \packages 文件夹基于 nuget.config HintPath 在项目文件中。这也是为什么可以在项目文件夹的根目录中看到nuget包的原因。

    但是,中的路径和版本不正确 文件.csproj ( ),应该是:

    <HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
    

    单身 ..\ 版本是3.0.1。

    3) 如何从vs a config for nuget导出以安装所有软件包?

    有一个 packages.config 在您的项目中,您可以使用Visual Studio中的Package Manager控制台安装所有软件包,但不能使用nuget CLI安装所有软件包。因为包管理器控制台提供对visual studio对象的访问。

    another thread 更多细节。

    希望这有帮助。

    推荐文章