2

我正在使用 Visual Studio 2015,我有一个包含 2 个不同 Web 应用程序的解决方案。存在一个解决方案及其下的两个项目。与 nuget 相关的文件分布为:

  1. 包文件夹位于解决方案目录中
  2. 每个项目目录下的 Package.config

我的解决方案中没有 nuget 文件夹:nuget.config 和 nuget.exe。

我的项目在 Visual Studio 中构建并运行良好,但是在将 VSTS 持续集成与构建解决方案步骤(使用映射到一个项目的构建定义)结合使用时遇到了一个问题,它给出了:

This project references NuGet package(s) that are missing on this computer. Use 
NuGet Package Restore to download them. For more information, see  The missing file is 
..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.

这是 MyProject.csproj 文件:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
  <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')" />
  <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>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{BBD26A49-D1F4-4391-9D60-2469433DEE0D}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>AdminUI</RootNamespace>
    <AssemblyName>AdminUI</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <MvcBuildViews>false</MvcBuildViews>
    <UseIISExpress>true</UseIISExpress>
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <UseGlobalApplicationHostFile />
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

我注意到它只尝试导入生成错误的包,但它没有显式导入其他包,而是将它们作为引用包含在内:

<Reference Include="WebGrease">
      <Private>True</Private>
      <HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
    </Reference>
    <Reference Include="Antlr3.Runtime">
      <Private>True</Private>
      <HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
    </Reference>

这也是myProject.csproj文件的结尾:

<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\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
  </Target>

我想知道为什么它会给出这个错误,考虑到这个包已经在上一步 "Nugget Install"中安装了。为什么它找不到?我在这个问题上花了很多时间!

4

3 回答 3

1

在添加构建任务之前,您可以添加 nuget install 或 restore 任务。这将在构建代理上恢复/安装 nuget 包。

于 2016-04-25T19:47:37.550 回答
0

确保Package.config您提到的文件存在于源代码管理中。

当持续集成代理尝试下载和构建项目时,可能所有内容都在您的机器上成功构建,因为Package.config存在但不在源代码控制中。

于 2020-05-18T17:21:21.427 回答
0

实际上,这对我有用:

将映射(存储库配置)添加到解决方案中的 packages 文件夹

存储库配置

在此处输入图像描述

Nuget 安装配置

在此处输入图像描述

然后,它就像一个魅力。

于 2016-04-26T19:00:09.870 回答