NuGet package restore for solution fails (only on the command line)

馋奶兔 提交于 2019-12-07 08:37:01

问题


I've recently switched to NuGet's latest recommended method which is using a `packages.json' file for projects:

{
  "dependencies": {
    "Newtonsoft.Json": "9.0.1",
    "RestSharpSigned": "105.2.3"
  },
  "frameworks": {
    "net45": {}
  },
  "runtimes": {
    "win": {}
  }
}

This works great in my local visual studio environment, but the CI server can no longer build the project.

What's odd is that I can see the packages being successfully restored for the solution, but on build, MSBuild has no idea where those DLLs are and all references to them fail:

Package Restore Succeeding:

09:48:07 Updating NuGet.exe to 3.4.4-rtm-final.
09:48:07 Update successful.
09:48:08 MSBuild auto-detection: using msbuild version '14.0' from 
         'C:\Program Files (x86)\MSBuild\14.0\bin'.
09:48:09 Restoring packages for C:\jenkins-test\...\Client\Client.NET45.project.json...
09:48:10 Installing RestSharpSigned 105.2.3.
09:48:10 Installing Newtonsoft.Json 9.0.1.
09:48:13 Committing restore...
09:48:13 Committing restore...
09:48:13 C:\jenkins-test\...\Client\Client.NET45.csproj
09:48:13 Restore completed in 3715ms.09:48:13 Installed:
09:48:13     2 package(s) to C:\jenkins-test\...\Client\Client.NET45.csproj

Build Failing:

09:48:14 Microsoft (R) Build Engine version 14.0.23107.0
...
09:48:14 Project "C:\jenkins-test\...\Client.sln" (1) is building 
         "C:\jenkins-test\...\Client\Client.NET45.csproj" (2) on node 1 (default targets).
09:48:14 PrepareForBuild:
09:48:14   Creating directory "bin\Debug\net45\".
09:48:14   Creating directory "obj\Debug\".
09:48:14 CoreCompile:
09:48:14   C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /doc:bin\Debug\net45\Client.xml /define:DEBUG;TRACE;NET45 /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Runtime.Serialization.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\WindowsBase.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Client.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /utf8output API\API.Authentication.cs API\API.Configuration.cs API\API.Parameters.cs API\API.Requests.cs API\API.Utilities.cs API\Authentication\AccessTokenStatus.cs API\Authentication\AuthenticationStatus.cs API\Authentication\BasicAuthenticationToken.cs API\Authentication\IAccessToken.cs API\Authentication\OauthAccessToken.cs "API\Custom Exceptions\APIRequestException.cs" "API\Custom Exceptions\NotWaitingException.cs" API\ExtensionMethods\ExtensionMethods.IAPIResourceView.cs API\ExtensionMethods\ExtensionMethods.IAPIResource_WithDataEndpoint.cs API\ExtensionMethods\ExtensionMethods.IAPIType.cs API\ExtensionMethods\ExtensionMethods.Reference.cs API\ExtensionMethods\ExtensionMethods.Rest.cs API\ExtensionMethods\ExtensionMethods.Rest.InferredType.cs API\JsonConverters\AnalyzeReContractResolver.cs API\JsonConverters\AnalyzeReJsonConverter.cs API\JsonConverters\ComplexNestedObjectConverter.cs API\JsonConverters\DerivedResourceCreationConverter.cs API\JsonConverters\JsonCreationConverter.cs "API\JsonConverters\JsonCreationConverter[T].cs" API\JsonConverters\JsonSerializerExtensionMethods.cs API\JsonConverters\LayerViewCreationConverter.cs API\JsonConverters\PortfolioViewSerializer.cs API\JsonConverters\ReferenceConverter.cs API\JsonConverters\UriConverter.cs API\LargeDataUpload\AdaptiveBufferedBytesProducer.cs API\LargeDataUpload\BufferedBytes.cs API\LargeDataUpload\BufferedBytesFromStreamProducer.cs API\LargeDataUpload\BufferedBytesResizer.cs API\LargeDataUpload\BufferedBytesToStringProducer.cs API\LargeDataUpload\BufferProducerException.cs API\LargeDataUpload\GZipBufferedBytesProducer.cs "API\LargeDataUpload\Internal Classes\LargeDataUpload.AsyncParameters.cs" "API\LargeDataUpload\Internal Classes\LargeDataUpload.Exceptions.cs" "API\LargeDataUpload\Internal Classes\LargeDataUpload.HandleUploadInSessionStrategy.cs" "API\LargeDataUpload\Internal Classes\LargeDataUpload.Parameters.cs" "API\LargeDataUpload\Internal Classes\LargeDataUpload.StatusReponse.cs" API\LargeDataUpload\IProducerConsumerBuffer.cs API\LargeDataUpload\LargeDataUpload.cs API\LargeDataUpload\ProducerConsumerBuffer.cs API\Rest\IRestResponse.cs API\Rest\Method.cs API\Rest\Parameter.cs API\Rest\ParameterType.cs API\Rest\ResponseStatus.cs API\Rest\RestResponse.cs "API\Rest\RestResponse[T].cs" Attributes\APITypeAliasAttribute.cs Attributes\GreaterThanAttribute.cs Attributes\LessThanAttribute.cs Attributes\NotEmptyAttribute.cs Attributes\NotNullAttribute.cs Attributes\NumericValidationAttribute.cs Attributes\PropertyAlias.cs Attributes\ResolvedInViews.cs Attributes\ServerGenerated.cs Attributes\ServerHasDefault.cs Attributes\ServerHasDefaultEmptyObject.cs Attributes\ValidationAttribute.cs Model\APITypes\APIResource_WithDataEndpoint.cs Model\APITypes\APIType_Polymorphic.cs Model\APITypes\Interfaces\IAPIResource_WithDataEndpoint.cs Model\APITypes\Interfaces\IAPI_Polymorphic.cs Model\APITypes\Interfaces\IStoredAPIResource.cs Model\APITypes\OptionsResponse.cs "Model\APITypes\REST Entities\ResourceStringBuilder.cs" "Model\APITypes\REST Entities\SubResources\CommandSubResource.cs" "Model\APITypes\REST Entities\SubResources\DataSubResource.cs" "Model\APITypes\REST Entities\SubResources\LargeDataSubResource.cs" "Model\APITypes\REST Entities\SubResources\ResourceEndpoint.cs" "Model\APITypes\REST Entities\SubResources\SubResource[T].cs" Model\APITypes\ServerError.cs Model\APITypes\StoredAPIResource.cs Model\APITypes\StoredAPIResource_Polymorphic.cs Model\Common\APIResource.cs Model\Common\APIResourceView\AggregationMethod.cs Model\Common\APIResourceView\BaseAPIResourceView.BackAllocations.cs Model\Common\APIResourceView\BaseAPIResourceView.CoMetrics.cs Model\Common\APIResourceView\BaseAPIResourceView.cs Model\Common\APIResourceView\BaseAPIResourceView.ExceedanceProbabilities.cs Model\Common\APIResourceView\BaseAPIResourceView.TailMetrics.cs Model\Common\APIResourceView\IAPIResourceView.cs Model\Common\APIResourceView\State.cs Model\Common\APIResourceView\TargetCurrencyDefault.cs Model\Common\APIResourceView\YELTSimulationResult.cs Model\Common\APIResourceView\YLTSimulationResult.cs Model\Common\APIType.cs Model\Common\CollectionResponse\CollectionResponseMeta.cs "Model\Common\CollectionResponse\CollectionResponse[T].cs" "Model\Common\CollectionResponse\ICollectionResponse[T].cs" Model\Common\Interfaces\IAPIResource.cs Model\Common\Interfaces\IAPIType.cs Model\Common\MonetaryUnit.cs "Model\Common\Perspective\Internal Classes\Perspective.BasicPerspective.cs" "Model\Common\Perspective\Internal Classes\Perspective.CustomizablePerspective.cs" "Model\Common\Perspective\Internal Classes\Perspective.LossNetOfTermsPerspective.cs" Model\Common\Perspective\Perspective.cs Model\Common\Perspective\Perspective.Enum.cs Model\Common\Perspective\Perspective.Static.cs Model\Common\Reference\IReference.cs "Model\Common\Reference\IReference[T].cs" Model\Common\Reference\Reference.cs "Model\Common\Reference\Reference[T].cs" Model\Common\Reinstatement.cs Model\Common\TaskStatus.cs Model\Metrics\BackAllocations\BackAllocations.cs Model\Metrics\CoMetrics\CoMetrics.Context.cs Model\Metrics\CoMetrics\CoMetrics.cs Model\Metrics\ExceedanceProbabilities\ExceedanceProbability.Context.cs Model\Metrics\ExceedanceProbabilities\ExceedanceProbability.cs Model\Metrics\TailMetrics\TailMetrics.Context.cs Model\Metrics\TailMetrics\TailMetrics.cs Model\Resources\Agent.cs Model\Resources\AnalysisProfile.cs "Model\Resources\Analysis\Abstract Base Classes\Analysis.cs" Model\Resources\Analysis\VendorPortfolioAnalysis.cs Model\Resources\Analysis\VendorTreatyAnalysis.cs "Model\Resources\Distributions\Abstract Base Classes\ContinuousDistribution.cs" "Model\Resources\Distributions\Abstract Base Classes\CustomDistribution.cs" "Model\Resources\Distributions\Abstract Base Classes\DiscreteDistribution.cs" "Model\Resources\Distributions\Abstract Base Classes\Distribution.cs" Model\Resources\Distributions\BinomialDistribution.cs Model\Resources\Distributions\CustomFrequencyDistribution.cs Model\Resources\Distributions\CustomSeasonalityDistribution.cs Model\Resources\Distributions\CustomSeverityDistribution.cs Model\Resources\Distributions\DiracDistribution.cs Model\Resources\Distributions\LogNormalDistribution.cs Model\Resources\Distributions\NegativeBinomialDistribution.cs Model\Resources\Distributions\NormalDistribution.cs Model\Resources\Distributions\ParetoDistribution.cs Model\Resources\Distributions\PoissonDistribution.cs Model\Resources\Distributions\UniformDistribution.cs Model\Resources\Distributions\UniformIntDistribution.cs Model\Resources\EventCatalog.cs Model\Resources\ExchangeRateProfile\ExchangeRateProfile.cs "Model\Resources\ExchangeRateProfile\Internal Classes\ExchangeRateProfile.ExchangeRateDateRule.cs" "Model\Resources\ExchangeRateProfile\Internal Classes\ExchangeRateProfile.ExchangeRateLatestRule.cs" "Model\Resources\ExchangeRateProfile\Internal Classes\ExchangeRateProfile.ExchangeRateSelectionRule.cs" Model\Resources\ExchangeRateTable.cs Model\Resources\File.cs "Model\Resources\Layers\Abstract Base Classes\Layer.cs" "Model\Resources\Layers\Abstract Base Classes\Layer_WithLossSets.cs" "Model\Resources\Layers\Abstract Base Classes\Layer_WithTerms.cs" "Model\Resources\Layers\Abstract Base Classes\Layer_XL.cs" Model\Resources\Layers\AggregateQuotaShare.cs Model\Resources\Layers\AggXL.cs Model\Resources\Layers\CatXL.cs Model\Resources\Layers\Filter.cs Model\Resources\Layers\Generic.cs Model\Resources\Layers\IndustryLossWarranty.cs Model\Resources\Layers\Interfaces\ILayer.cs Model\Resources\Layers\Interfaces\ILayer_WithAggregateTerms.cs Model\Resources\Layers\Interfaces\ILayer_WithLossSets.cs Model\Resources\Layers\Interfaces\ILayer_WithOccurrenceTerms.cs Model\Resources\Layers\Interfaces\ILayer_WithReinstatements.cs Model\Resources\Layers\Interfaces\ILayer_WithTerms.cs Model\Resources\Layers\Nested.cs Model\Resources\Layers\QuotaShare.cs Model\Resources\Layers\SurplusShare.cs Model\Resources\LayerViews\ILayerView.cs "Model\Resources\LayerViews\ILayerView[T].cs" Model\Resources\LayerViews\LayerViews.cs "Model\Resources\LayerViews\LayerView[T].cs" "Model\Resources\LossFilters\Abstract Base Classes\AttributeFilter.cs" "Model\Resources\LossFilters\Abstract Base Classes\ComparisonFilter.cs" "Model\Resources\LossFilters\Abstract Base Classes\ExpressionFilter.cs" "Model\Resources\LossFilters\Abstract Base Classes\LossFilter.cs" Model\Resources\LossFilters\AndFilter.cs Model\Resources\LossFilters\AnyFilter.cs Model\Resources\LossFilters\AnyOfFilter.cs Model\Resources\LossFilters\GTFilter.cs Model\Resources\LossFilters\LTFilter.cs Model\Resources\LossFilters\OrFilter.cs Model\Resources\LossFilters\RangeFilter.cs "Model\Resources\LossSets\Abstract Base Classes\LossSet.cs" "Model\Resources\LossSets\Abstract Base Classes\LossSet_WithCurrency.cs" "Model\Resources\LossSets\Abstract Base Classes\LossSet_WithData.cs" Model\Resources\LossSets\ELTLossSet.cs Model\Resources\LossSets\Interfaces\ILossSet_Simulated.cs Model\Resources\LossSets\Interfaces\ILossSet_WithEventCatalog.cs Model\Resources\LossSets\Interfaces\ILossSet_WithSeasonality.cs "Model\Resources\LossSets\Internal Classes\BinaryYELTConverter.cs" "Model\Resources\LossSets\Internal Classes\InuringTerms.cs" "Model\Resources\LossSets\Internal Classes\LossSetProfile.cs" "Model\Resources\LossSets\Internal Classes\LossType.cs" "Model\Resources\LossSets\Internal Classes\NestedLayerLossSet.Perspective.cs" "Model\Resources\LossSets\Internal Classes\TreatyLossSet.Treaty.cs" Model\Resources\LossSets\LoadedLossSet.cs Model\Resources\LossSets\NestedLayerLossSet.cs Model\Resources\LossSets\ParametricLossSet.cs Model\Resources\LossSets\PortfolioLossSet.cs Model\Resources\LossSets\TreatyLossSet.cs Model\Resources\LossSets\YELTLossSet.cs Model\Resources\LossSets\YLTLossSet.cs "Model\Resources\OptimizationView\Internal Classes\OptimizationView.Candidate.cs" "Model\Resources\OptimizationView\Internal Classes\OptimizationView.CandidateParameter.cs" "Model\Resources\OptimizationView\Internal Classes\OptimizationView.DomainEntry.cs" "Model\Resources\OptimizationView\Internal Classes\OptimizationView.Result.cs" Model\Resources\OptimizationView\OptimizationView.cs "Model\Resources\Portfolios\Abstract Base Classes\Portfolio.cs" Model\Resources\Portfolios\DynamicPortfolio.cs Model\Resources\Portfolios\StaticPortfolio.cs Model\Resources\PortfolioView\PortfolioView.cs Model\Resources\Simulation\Simulation.cs Model\Resources\Simulation\StaticSimulation.cs Utilities\Formatting.cs Utilities\IfNotNullExtensionMethod.cs Utilities\ReflectionUtilities.cs "Utilities\Simulation Monitor\AsyncRequestMonitor.cs" "Utilities\Simulation Monitor\SimulationStatus.cs" "Utilities\Simulation Monitor\SimulationStatusMonitor.cs" Utilities\TypeResolver.cs Properties\AssemblyInfo.cs Properties\Settings.Designer.cs "C:\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.cs"
09:48:23 API\API.Configuration.cs(9,20): error CS0246: The type or namespace name
'RestSharp' could not be found (are you missing a using directive or an assembly reference?)
...
09:48:23 API\ExtensionMethods.IAPIType.cs(2,7): error CS0246: The type or namespace name
'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
...
09:48:25     0 Warning(s)
09:48:25     258 Error(s)
09:48:25 
09:48:25 Time Elapsed 00:00:01.27

This is my build script right now:

nuget.exe update -Self
nuget.exe restore Client.sln
MSBuild.exe Client.sln /p:Configuration=Release

Never had problems with it before switching to the packages.json method of restoring solutions (which requires removing the references from the csproj files)

From what I can tell, the referenced dlls from NuGet are not getting linked into the build (they don't appear anywhere in the really long CoreCompile line).

Do I need to change something in my CI build script to get it working again?


回答1:


In order for MSBuild to resolve the assemblies from the project.json file it uses a custom MSBuild task which is installed on the machine so it is globally available for MSBuild.

On your local machine these will be in the directory:

C:\Program Files (x86)\MSBuild\Microsoft\NuGet

I believe these files are installed by Visual Studio 2015.

There is also a Microsoft.NuGet.ImportBefore.props file in the directory:

C:\Program Files (x86)\MSBuild\14.0\Imports\Microsoft.Common.Props\ImportBefore

There is also a Microsoft.NuGet.ImportAfter.targets file in the directory:

C:\Program Files (x86)\MSBuild\14.0\Imports\Microsoft.Common.Targets\ImportAfter

Which is how the NuGet .props and .targets files are imported into MSBuild and made available to every project.



来源:https://stackoverflow.com/questions/38100358/nuget-package-restore-for-solution-fails-only-on-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!