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

4
我在构建我的解决方案,包括一个单元测试项目时,遇到了以下错误:

此项目引用了在此计算机上缺失的 NuGet 包。请使用 NuGet 包还原来下载它们。有关详细信息,请参阅 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)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
    </Reference>
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="GenerateConceptService\GenerateConceptServiceUnitTest.cs" />
    <Compile Include="SocialMedia\SocialMediaServiceTest.cs" />
    <Compile Include="SocialMedia\TwitterActionsTest.cs" />
    <Compile Include="UnitTest1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="packages.config" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Core.WindowsServices\Core.GenerateConcept\Core.GenerateConcept.csproj">
      <Project>{767FA3B9-55C4-4C3D-AEB8-7912A09AF868}</Project>
      <Name>Core.GenerateConcept</Name>
    </ProjectReference>
    <ProjectReference Include="..\CoreApi2\CoreApi2.Api\CoreApi2.Api.csproj">
      <Project>{55466732-A2A7-479D-B4A1-99FB2732DCE6}</Project>
      <Name>CoreApi2.Api</Name>
    </ProjectReference>
    <ProjectReference Include="..\CoreApi2\CoreApi2.Model\CoreApi2.Model.csproj">
      <Project>{24fba440-a133-4024-87c9-a77d0b7af659}</Project>
      <Name>CoreApi2.Model</Name>
    </ProjectReference>
    <ProjectReference Include="..\CoreApi2\CoreApi2.Services\CoreApi2.Services.csproj">
      <Project>{d2a117bf-d7e5-4483-bb35-71336b8e8404}</Project>
      <Name>CoreApi2.Services</Name>
    </ProjectReference>
    <ProjectReference Include="..\Infrastructure\Informanagement.Infrastructure\Informanagement.Infrastructure.csproj">
      <Project>{92C12E85-209B-4F16-BB1E-B1E120EFB4EB}</Project>
      <Name>Informanagement.Infrastructure</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props'))" />
    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets'))" />
  </Target>
  <Import Project="..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets')" />
</Project>

我有损坏的引用:

在这里输入图片描述


你使用了“NuGet包恢复”吗?他们甚至提供了如何执行此操作的链接。 - SᴇM
可能是[NuGet包丢失]的重复问题(https://dev59.com/g1wY5IYBdhLWcg3wwqA5)。 - SᴇM
2
是的,我执行了“NuGet包还原”,但错误仍然存在。 - Irshad Ahmed Akhonzada
请检查您的NuGet源。 - Bola
1个回答

6

我已经找到了解决这个错误的方法,其实问题出在我的包文件夹里有一个不同版本的MSTest.TestAdapter(1.3.2),而在.csproj文件中引用的是MSTest.TestAdapter(1.1.0)。 我已经将所有MSTest.TestAdapter(1.1.0)替换为MSTest.TestAdapter(1.3.2),这解决了我的问题。


我在 c# 执行文件中无法保持对“MSTest.TestAdapter”的引用。在 VS 中查看项目时存在该引用,但在查看从该项目创建的可执行文件时丢失了该引用。我已经发布了一个 SO 问题。你上面使用的版本是“运行时版本”还是只是“版本”。 - user1207289

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接