带有project.json的.NET项目无法构建 [英] .NET project with project.json cannot be built
问题描述
我有.net应用,并且正在尝试从
I have .net app, and I am trying to migrate from
packages.config
至project.json
.
当我使用Vs 2015构建项目或从命令行手动使用MsBuild时,一切工作正常.当我使用以下设置在构建服务器上构建该问题时,该问题开始发生:
Everything works fine when I build the project with Vs 2015 or manually using MsBuild from a command line. The problem starts to happen when I build it on build server with the setup:
- .NET 4.51应用程序
- MSBuild 14.0.25402.0
- Windows Server 2012
- 已安装Microsoft Build Tools 2013、2015 RC.
- 未安装Visual Studio.
- Nuget 3.4.3.855
在创建nuget restore时,正在创建project.lock.json,程序包会下载到user/.nuget/packages中,因此看起来很正常.然后,我尝试运行MSBuild,并且遇到很多参考错误:
When doing nuget restore project.lock.json is being created, packages are downloaded to user/.nuget/packages so it looks like it's doing the job. Then I am trying to run MSBuild, and I am getting a lot of reference errors:
error CS0246: The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)
当我从开发人员机器上使用MSBuild时,即使我指向构建服务器目录,也可以构建该项目,因此MSBuild显然是一个问题.我想Microsoft Build Tools缺少什么,有什么主意吗?
When I use MSBuild from developer machine, I can build this project even if I point to build server directory so it's an obvious problem with MSBuild. I suppose that something is missing with Microsoft Build Tools, any ideas?
看起来msbuild在我的开发人员机器上的所有nuget路径中都添加了标记/reference,而在构建服务器机器上却没有这样做. 示例:
it looks like msbuild adds flag /reference with all nuget paths on my developer machine and it doesn't do it on build server machine. Example:
/reference:C:\Users\user\.nuget\packages\log4net\1.2.10\lib\log4net.dll
开发人员构建项目的机器:
Build started 27/06/2016 13:29:40.
Project "Y:\13dd0660b4e0a7a0\project.Shared.Utilities\project.Shared.Utilities.csproj" on node 1 (default targets).
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:C:\Users\username\.nuget\packages\EPPlus\4.0.4\lib\net20\EPPlus.dll
构建服务器msbuild来构建相同的项目
D:\13dd0660b4e0a7a0\project.Shared.Utilities>"C:\Program Files (x86)"\MSBuild\14.0\Bin\msbuild project.shared.utilities.csproj
Microsoft (R) Build Engine version 14.0.25123.0
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 27/06/2016 12:35:19.
Project "D:\13dd0660b4e0a7a0\project.Shared.Utilities\project.shared.utilities.csproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Debug\".
Creating directory "obj\Debug\".
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.ComponentModel.DataAnnotations.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Configuration.dll"
这只是日志的一部分->如您所见,/reference已传递到第一个脚本
This is only part of the log -> as you can see /reference is passed to the first script
推荐答案
我找到了解决方案. 如果缺少内容,则将内容从开发人员机器复制到构建服务器机器上的相应目录.
I have found the solution. Copy content from developer machine to corresponding directory on your build server machine if missing.
C:\Program Files (x86)\MSBuild\Microsoft\NuGet
不确定为什么在安装构建工具2015后会丢失此信息.
Not sure why this is missing after build tools 2015 installation.
这篇关于带有project.json的.NET项目无法构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!