dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

nuget pack with csproj throwing NullReferenceException at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance() #3667

Open nkolev92 opened 6 years ago

nkolev92 commented 6 years ago

From @rpajak-solarwinds on July 24, 2018 10:13

Details about Problem

NuGet version: 4.6.2.5055 OS version: Windows Server 2016, version 10.0 TeamCity version: 2018.1

NuGet is unable to pack a csproj. on a TeamCity agent(s). But have not found any reason why it should not work. Especially that the agents is building solutions without any problems, nuget restore also work properly. Locally (on developer environment) the nuget pack works fine.

Worked before? No.

Detailed repro steps so we can see the same problem

nuget pack "ConsoleApplication1\ConsoleApplication1.csproj" -Verbosity detailed -Properties Configuration=Release

Other suggested things

It might be some problems with MSBuild itself. The same issue occurs for NuGet 4.4.1.4656 Right now my workaround is not using the csproj for nuget pack, but defining everything inside the nupkg.

Verbose Logs

NuGet Version: 4.6.2.5055 Attempting to build package from 'ConsoleApplication1.csproj'. MSBuild auto-detection: using msbuild version '15.7.179.6572' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild. Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance() at Microsoft.Build.Shared.NativeMethodsShared.get_IsMono() at Microsoft.Build.BackEnd.Logging.LoggingService..ctor(LoggerMode loggerMode, Int32 nodeId) at Microsoft.Build.Evaluation.ProjectCollection.CreateLoggingService(Int32 maxCPUCount, Boolean onlyLogCriticalEvents) at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary2 globalProperties, IEnumerable1 loggers, IEnumerable1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents) at Microsoft.Build.Evaluation.ProjectCollection.get_GlobalProjectCollection() at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion)

Sample Project

Any C# console application with .NET Framework 4.5.2. There is no ConsoleApplication1.nuspec

Copied from original issue: NuGet/Home#7142

nkolev92 commented 6 years ago

From @zhili1208 on July 24, 2018 17:51

Could you try to update your VS on the agent to 15.7.5? I tried that version, can't repro the issue.

nkolev92 commented 6 years ago

From @rpajak-solarwinds on July 25, 2018 13:10

Updated to 15.7.5. Same issue. Probably it is environmental however MSBuild (?) should handle it. Maybe I should report it on https://github.com/Microsoft/msbuild/issues ?

nkolev92 commented 6 years ago

From @zhili1208 on July 25, 2018 20:41

maybe msbuild team have some clue. also I like to try your sample project to see if I can repro. But I think it should be related to environment.

nkolev92 commented 6 years ago

From @rpajak-solarwinds on July 26, 2018 6:9

sample project is a waste of time (really just a console application even without any nuget packages). on my development environment everything is working

nkolev92 commented 6 years ago

From @rpajak-solarwinds on August 28, 2018 12:55

any update? should I report it to msbuild team?