Visual studio 使用MSBuild进行NuGet还原失败
我有一个ASP.NET MVC 5项目,我正试图使用MSBuild在我们公司的构建服务器上构建该项目,但是该构建无法还原NuGet包。我正在使用Visual Studio 2015和TFS 我的项目结构如下所示:Visual studio 使用MSBuild进行NuGet还原失败,visual-studio,tfs,msbuild,nuget,nuget-package-restore,Visual Studio,Tfs,Msbuild,Nuget,Nuget Package Restore,我有一个ASP.NET MVC 5项目,我正试图使用MSBuild在我们公司的构建服务器上构建该项目,但是该构建无法还原NuGet包。我正在使用Visual Studio 2015和TFS 我的项目结构如下所示: 解决方案(.sln) 努吉先生 NuGet.config NuGet.targets 项目文件夹 项目项(参考、库等) 项目测试单元 单元测试项目 这是我的NuGet.config文件: <?xml version="1.0" encoding="utf-8"?&
- 解决方案(.sln)
- 努吉先生
- NuGet.config
- NuGet.targets
- 项目文件夹
- 项目项(参考、库等)
- 项目测试单元
- 单元测试项目
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">false</RequireRestoreConsent>
<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
<PackageSource Include="\\itliv-nas03\Development Team\NuGet\Packages" />
</ItemGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>
<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">\\itliv-nas03\Development Team\NuGet\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>
<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>
<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
- 我尝试了几种不同的方式编辑我的NuGet.targets文件,希望能够修复(尝试了不同的包源、不同的案例、删除/添加引号)
- 我已阅读了以下文件: 但没有成功
- 我已经更新到NuGet 3.3
Summary
Release | Any CPU
1 error(s), 0 warning(s)
$/Develop/Websites/VehicleLookupUI/VehicleLookupWebUI.sln - 1 error(s), 0 warning(s), View Log File
C:\Builds\1\Develop\VehicleLookupWeb-Develop\Sources\VehicleLookupUI\VehicleLookupWebUI\VehicleLookupWebUI.csproj (315): 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 ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.
$/Develop/Websites/VehicleLookupUI/VehicleLookupWebUI.sln compiled
No Test Results
No Code Coverage Results
Other Errors and Warnings
2 error(s), 0 warning(s)
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
TF270015: 'MSBuild.exe' returned an unexpected exit code. Expected '0'; actual '1'.
我感觉NuGet在错误的文件夹中查找丢失的包。我可以将源代码包括在工具>NuGet Package Manager中..>包管理器设置>NuGet包管理器>包源,但这仅适用于我在本地使用Visual Studio,而不使用尝试“开箱即用”构建它的MSBuild
我试图在TSF上构建,方法是打开Team Explorer>Builds,然后右键单击我的构建并选择Queue New build…请在以下位置的TFS build server上创建一个特殊的Nuget.config文件。
您正在使用MSBuild集成方式来还原包,为此,解决方案中有.nuget文件夹(包含nuget.exe、nuget.config和nuget.targets),需要添加到源代码管理中,而无需将nuget还原生成步骤/任务添加到生成定义中来还原包,因此,删除该步骤/任务,并在构建定义的存储库选项卡中将Clean设置为true。 我建议您迁移到自动恢复:
更多信息,请参阅文章。可能重复的请提供完整的关于NuGet restore path\to\solution.sln命令的信息,它是否恢复成功。
WARNING: Unable to find version '3.4.1.9004' of package 'Antlr'.
C:\Users\it-chrism\.nuget\packages\: Package 'Antlr.3.4.1.9004' is not found on source 'C:\Users\it-chrism\.nuget\packages\'.
C:\Users\it-chrism\AppData\Local\NuGet\Cache: Package 'Antlr.3.4.1.9004' is not found on source 'C:\Users\it-chrism\AppData\Local\NuGet\Cache'.
Summary
Release | Any CPU
1 error(s), 0 warning(s)
$/Develop/Websites/VehicleLookupUI/VehicleLookupWebUI.sln - 1 error(s), 0 warning(s), View Log File
C:\Builds\1\Develop\VehicleLookupWeb-Develop\Sources\VehicleLookupUI\VehicleLookupWebUI\VehicleLookupWebUI.csproj (315): 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 ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.
$/Develop/Websites/VehicleLookupUI/VehicleLookupWebUI.sln compiled
No Test Results
No Code Coverage Results
Other Errors and Warnings
2 error(s), 0 warning(s)
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
TF270015: 'MSBuild.exe' returned an unexpected exit code. Expected '0'; actual '1'.