无法在 Visual Studio 2017 中构建我的单元测试项目
Posted
技术标签:
【中文标题】无法在 Visual Studio 2017 中构建我的单元测试项目【英文标题】:Unable to build My Unit Test Project in Visual Studio 2017 【发布时间】:2018-10-25 07:31:38 【问题描述】:我在构建解决方案(包括单元测试项目)时遇到此错误。
此项目引用了此项目中缺少的 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 包还原”?他们甚至提供了如何做到这一点的链接。 NuGet Packages are missing的可能重复 是的,我做了“NuGet 包还原”,但错误仍然存在 检查你的 nuget 源 【参考方案1】:我解决了这个错误,实际上我的包文件夹中有不同版本的 MSTest.TestAdapter(1.3.2) 并且 .csproj
文件引用指向 MSTest.TestAdapter(1.1.0)。
我已将所有 MSTest.TestAdapter(1.1.0) 替换为 MSTest.TestAdapter(1.3.2),这解决了我的问题。
【讨论】:
我在维护 c# executable 中MSTest.TestAdapter
的参考时遇到问题。当我在 VS 中看到该项目时,参考就在那里,但当我查看从该项目创建的可执行文件时,它就丢失了。我开了一个 SO Question 。您上面使用的版本是runtime version
或只是version
。以上是关于无法在 Visual Studio 2017 中构建我的单元测试项目的主要内容,如果未能解决你的问题,请参考以下文章
win7安装visual studio 2017无法进入安装界面
Visual Studio 2017 - 无法安装 WDK 扩展
无法在 Visual Studio 2017 中更改程序集的默认语言
无法在 Visual Studio 2017 RC 中添加全局 JavaScript Intellisense 引用