相关疑难解决方法(0)

找不到类型或命名空间名称"System"

在Visual Studio 2015 Professional中打开我的项目时,我的所有视图(*.cshtml)中都存在以下错误(以及更多错误).

错误CS0246找不到类型或命名空间名称"System"(您是否缺少using指令或程序集引用?)严重性代码说明项目文件行

错误CS0518未定义或导入预定义类型"System.Object"严重性代码描述项目文件行

错误CS0518未定义或导入预定义类型"System.String"

我得到了这些参考:

<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Sitecore.Kernel, Version=7.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\Sitecore.Kernel.dll</HintPath>
</Reference>
<Reference Include="Sitecore.Mvc">
  <HintPath>N:\XXX\Sitecore.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>N:\XXX\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Providers">
  <HintPath>N:\XXX\System.Web.Providers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion> …
Run Code Online (Sandbox Code Playgroud)

c# .net-4.5 asp.net-mvc-5 visual-studio-2015

37
推荐指数
9
解决办法
8万
查看次数

Nuget无法恢复Microsoft.Net.Compilers.1.0.0

我正在尝试Microsoft.Net.Compilers.1.0.0使用Nuget Package Manager在VS 2017中安装/重新启动.在输出中,它显示恢复已完成.但是,当我检查packages文件夹时,我没有看到Microsoft.Net.Compilers文件夹.并且因为我得到了错误

严重级代码说明项目文件行抑制状态错误此项目引用此计算机上缺少的NuGet程序包.使用NuGet Package Restore下载它们.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105.丢失的文件是....\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.XXXXX\Src\Api\Api.csproj 296

在csproj文件中,顶部有一行

<Import Project="..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
Run Code Online (Sandbox Code Playgroud)

背景
此问题发生在具有目标框架4.6.2的Web API项目中.我也有NET Standard 1.4我想与不同类型的.NET应用程序共享的库.当我添加NET Standard LibraryWeb API项目的引用时,我错过了依赖项问题.所以根据我的建议我编辑.csproj文件并添加

  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Run Code Online (Sandbox Code Playgroud)

这解决了缺少的依赖问题.

然后我删除package.config文件,从packages文件夹中删除所有包并添加回所有包(除了我无法添加Microsoft.Net.Compilers).包引用现在位于.csproj文件中

SO张贴在这里,但在我的情况下Microsoft.Net.Compilers甚至不得到恢复到packages文件夹中.VS 2017显示恢复完成但我不知道它实际上在哪里处理文件.(除非文件夹名称与Microsoft.Net.Compilers不同)

我原来的package.config文件有这一行

<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net462" developmentDependency="true" />
Run Code Online (Sandbox Code Playgroud)

现在我的.csproj文件

   <PackageReference Include="Microsoft.Net.Compilers">
      <Version>1.0.0</Version>
    </PackageReference>
Run Code Online (Sandbox Code Playgroud)

更新1
因此,当启用packagereference时,nuget将在C:\Users\{username}\.nuget\packages文件夹中 安装软件包

这意味着我需要使用正确的相对路径更新csproj文件.

这个包文件夹的相对路径是什么?

nuget nuget-package nuget-package-restore visual-studio-2017 .net-standard

10
推荐指数
2
解决办法
8761
查看次数

VS2017无法发现MSTest测试

我的一些.Net框架4.5和4.6和4.7项目没有通过测试资源管理器发现他们的测试,我一直有这个反复出现的问题."测试"日志输出显示:

The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

这就是我拥有的所有信息.

我已经尝试了不同版本MSTest.Framework和适配器等的每个组合.只是想不出来这个.我已经完成了测试扩展缓存清理.

c# mstest visual-studio-2017

7
推荐指数
1
解决办法
1727
查看次数

无法在 Visual Studio 2017 中构建我的单元测试项目

当我构建解决方案(包括单元测试项目)时,我收到此错误。

此项目引用了该计算机上缺少的 NuGet 包。使用 NuGet Package Restore 下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 ..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets。

.csproj 文件

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{77FE5641-248D-4D82-850A-1B53495CB9A9}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>UnitTest</RootNamespace>
    <AssemblyName>UnitTest</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
    <IsCodedUITest>False</IsCodedUITest>
    <TestProjectType>UnitTest</TestProjectType>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
    <TargetFrameworkProfile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing visual-studio

4
推荐指数
1
解决办法
3809
查看次数

NuGet参考存储在哪里?

我无法获得这个C#解决方案(点击下载 - 666MB在这里浏览GitHub)来编译:

我得到的错误是

此项目引用此计算机上缺少的NuGet包.使用NuGet Package Restore下载它们.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105.丢失的文件是..\packages\Accord.3.8.0\build\Accord.targets.bootcamp_basecamera C:\ Users\MyUser\Desktop\ComputerVision_Bootcamp-master\bootcamp_basecamera\bootcamp_basecamera\bootcamp_basecamera.csproj 144

boot_camp_basecamera.csproj中有问题的行是:

<Error Condition="!Exists('..\packages\Accord.3.8.0\build\Accord.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Accord.3.8.0\build\Accord.targets'))" />
Run Code Online (Sandbox Code Playgroud)

我已经在StackOverflow上查看了每个NuGet问题/解决方案,但没有一个答案对我有用.

我尝试了包恢复,我手动卸载了所有NuGet包并再次安装它们.

这并没有使错误消息消失.

因此,我想问一下这个错误消息来自何处.它说"这个项目引用......".我甚至删除了package.config文件,我仍然看到这个错误.

因此,我想问一下这个引用存储的位置,因为它不能是packages.config(因为我删除了它们).

谢谢.

根据请求,这是有问题的.csproj文件的内容:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\packages\OpenCvSharp3-AnyCPU.3.3.1.20171117\build\OpenCvSharp3-AnyCPU.props" Condition="Exists('..\packages\OpenCvSharp3-AnyCPU.3.3.1.20171117\build\OpenCvSharp3-AnyCPU.props')" />
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{10F276C8-F8C8-43FB-90F3-B3F1F0B74A2C}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <RootNamespace>Bootcamp.CompVis.Webinar</RootNamespace>
    <AssemblyName>webinar</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>x64</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel> …
Run Code Online (Sandbox Code Playgroud)

c# nuget

3
推荐指数
1
解决办法
816
查看次数