Search code examples
c#.net-corenancyproject.jsondotnet-cli

Unable to build new projects in .NET Core using project.json but existing ones build/restore fine


So the short version here is that my old existing repo's that utilize a global.json and project.json (all Nancy projects) work perfectly fine with no issue.

However, if I attempt to create a new folder structure with the identical global.json, project.json, and file structure, I get the error below when attempting anything with the cli:

C:\VSCode\DispoStatService> dotnet restore A JSON parsing exception occurred in [C:\VSCode\DispoStatService\global.json]: * Line 1, Column 2 Syntax error: Malformed token MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file

See screenshot as well for more detail: DotNetCLI Examples


Solution

  • As it turns out, I did not really find the ultimate problem or solution for what was happening here. As we so often do, though, I got it to work.

    I'm assuming perhaps just starting with a different set of files (since the error was consistently telling me there was a bad character in global.json) did the trick.

    tl;dr - I basically just copied a separate NancyFX project template I already had

    • It did use a different sdk/cli version but I don't think that was the real culprit here
    • I then renamed all my namespaces to match the new project

    Ultimately, my project.json

    {
      "name": "DispoStatsService",
      "version": "1.0.0-beta",
      "buildOptions": {
        "debugType": "portable",
        "emitEntryPoint": true
      },
      "dependencies": {
        "Microsoft.AspNetCore.Owin": "1.1.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
        "Microsoft.Extensions.Configuration.Json": "1.1.0",
        "Microsoft.AspNetCore.Diagnostics": "1.1.0",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
        "Microsoft.Extensions.Configuration.Binder": "1.1.0",
        "Microsoft.AspNetCore.StaticFiles": "1.1.0",
        "Nancy": "2.0.0-clinteastwood",
        "Dapper": "1.50.2"
      },
     "frameworks": {
        "netcoreapp1.1": {
          "imports": [
            "dotnet5.6",
            "dnxcore50",
            "portable-net45+win8"
          ],
          "dependencies": {
            "Microsoft.NETCore.App": {
              "type": "platform",
              "version": "1.1.0"
            }
          }
        }
      },
      "tools": {
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
          "version":"1.1.0-preview4-final",
          "imports": "portable-net45+win8+dnxcore50"
        }
      },
      "runtimeOptions": {
        "configProperties": {
          "System.GC.Server": true
        }
      },
    
      "publishOptions": {
        "include": [
          "wwwroot",
          "web.config",
          "appsettings.json",
          "Content"
        ]
      },
    
      "scripts": {
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      }
    }
    

    and my global.json

    {
      "projects": [ "src", "test" ],
      "sdk": {
        "version": "1.0.0-preview2-003131"
      }
    }
    

    See directory structure here: enter image description here