当我在安装了.NET Core 1.0 SDK和Tooling(预览2)的Visual Studio 2015(Update 3)中创建默认Web项目并在还原本地源代码控制更改后重新启动Visual Studio时,我得到以下编译错误:
无法使以下项目可运行:MyDefaultWebProject(.NETCoreApp,Version = v1.0)原因:对象引用未设置为对象的实例。
根据Visual Studio,错误位于第262行的C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets
在这一行上有以下代码:
<Dnx
RuntimeExe="$(SDKToolingExe)"
Condition="'$(_DesignTimeHostBuild)' != 'true'"
ProjectFolder="$(MSBuildProjectDirectory)"
Arguments="$(_BuildArguments)"
/>
我该如何解决这个问题?
答案 0 :(得分:21)
我设法找到的唯一可行解决方案是运行dotnet restore
命令:
C:\Dev\*****>dotnet restore
Welcome to .NET Core!
---------------------
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.
Decompressing 100% 2181 ms
Expanding 100% 9113 ms
log : Restoring packages for C:\Dev\*****\project.json...
log : Restoring packages for tool 'BundlerMinifier.Core' in C:\Dev\*****\project.json...
log : Restoring packages for tool 'Microsoft.AspNetCore.Razor.Tools' in C:\Dev\*****\project.json...
log : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in C:\Dev\*****\project.json...
log : Restoring packages for tool 'Microsoft.EntityFrameworkCore.Tools' in C:\Dev\*****\project.json...
log : Restoring packages for tool 'Microsoft.Extensions.SecretManager.Tools' in C:\Dev\*****\project.json...
log : Restoring packages for tool 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' in C:\Dev\*****\project.json...
log : Writing lock file to disk. Path: C:\Dev\*****\project.lock.json
log : C:\Dev\*****\project.json
log : Restore completed in 13207ms.
之后,Visual Studio中的编译再次成功。
答案 1 :(得分:1)
在我的情况下,问题是当我从源代码控制中提取源时,解决方案中的一个类库项目是通过绝对路径引用AspNetCore.Identity
库。因此 - project.fragment.lock.json
文件中生成了错误的路径,无法构建解决方案。
修复.csproj
文件中的绝对路径引用使其工作。