Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predefined type 'System.Void' is not defined or imported during Visual Studio Online build of ASP.NET 5

I get this error when I try to build the project in Visual Studio Online:

…\Frontend\Startup.cs(65,49): Error CS0518: Predefined type 'System.Void' is not defined or imported
…\Frontend\Startup.cs(65,49): DNXCore,Version=v5.0 error CS0518: Predefined type 'System.Void' is not defined or imported [C:\a\1\s\Frontend\src\Frontend\Frontend.xproj]

It seems that the error happens in the place where I reference another library (package class library).

P.S. I had some conversation about this here: Easy way to build and deploy (to Azure) ASP.NET 5 in Visual Studio Team Services, but there was no answer after all, so I still cannot build it...

Web project.json:

"dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Web.Common": "1.0.0-*"
},

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }
},

Library project.json

"frameworks": {
    "dnx451": { },
    "dnxcore50": {
        "dependencies": {
            "Microsoft.CSharp": "4.0.1-beta-23516",
            "System.Collections": "4.0.11-beta-23516",
            "System.Linq": "4.0.1-beta-23516",
            "System.Runtime": "4.0.21-beta-23516",
            "System.Threading": "4.0.11-beta-23516"
      }
    }
  },
"dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final"
  }

Update (problem and solution):

The problem was in the fact that my library reference was not in the same folder and the script by default does not run dnu-restore there, so I had to go one level up and start finding project.json recursively there

$SourceRoot = Split-Path -Path $PSScriptRoot -Parent

# run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
Get-ChildItem -Path $SourceRoot -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

Thanks Eddie - MSFT for help!

like image 695
Ilya Chernomordik Avatar asked Jan 05 '16 08:01

Ilya Chernomordik


2 Answers

Restart visual studio it will resolve the problem. It was the case for me.

like image 126
Jean BIDI Avatar answered Nov 11 '22 19:11

Jean BIDI


In my own issue, I rebuilt the entire solution and the errors just disappeared.

like image 29
superninja Avatar answered Nov 11 '22 19:11

superninja