Microsoft.DotNet.Common.Targets(262,5): error : Ob

2019-05-10 01:02发布

问题:

I am migrating a library from .Net 4.5 to .net core. I already have the .xproj in place, but when I run dotnet build I get the error:

Microsoft.DotNet.Common.Targets(262,5): error : Obje ct reference not set to an instance of an object.

this is my project.json file:

{
  "version": "1.0.0",

  "frameworks": {
    "net45": {
      "frameworkAssemblies": {
        "System.Collections.Concurrent": {
          "type": "build"
        }
      }
    },
    "netstandard1.6": {
      "imports": "dnxcore50",
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  }
}

is there something I'm missing?

回答1:

Running dotnet restore from command line worked but not from Visual Studio 2015 Update 3. I suspect this has something to do with having private nuget feeds.



回答2:

If you get this error on a TFS build on a remote server you can still run dotnet restore manually.

eg. I switched to C:\BUILD-AGENT\_work\1\s\RR.CRM and ran dotnet restore

Still not quite sure when VS does this or doesn't do it, but for now it was a quick fix that worked.



回答3:

I had the same problem in VS2015 (Community) starting a ASP.NET MVC Core project from scratch and updating to Core 1.1.1. For some unknown reason, Nuget does not update 100% of the references; some of them remain a "step behind".

Below you can find my project.json file

{
  "dependencies": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.1.0-preview4-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.1.1",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.1",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.1",
    "Microsoft.AspNetCore.Diagnostics": "1.1.1",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.1",
    "Microsoft.AspNetCore.Mvc": "1.1.2",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.1",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.1",
    "Microsoft.AspNetCore.StaticFiles": "1.1.1",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": {
      "version": "1.1.1",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.1.0",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.1",
    "Microsoft.Extensions.Configuration.Json": "1.1.1",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.1",
    "Microsoft.Extensions.Logging": "1.1.1",
    "Microsoft.Extensions.Logging.Console": "1.1.1",
    "Microsoft.Extensions.Logging.Debug": "1.1.1",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
    "Microsoft.NETCore.App": {
      "version": "1.1.1",
      "type": "platform"
    },
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.1.0-preview4-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.1.0",
      "type": "build"
    }
  },

  "tools": {
    "BundlerMinifier.Core": "2.4.337",
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.1.0-preview4-final",
      "imports": [
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Microsoft.AspNetCore.Razor.Tools did not update correctly. Microsoft.VisualStudio.Web.CodeGeneration.Tools and Microsoft.VisualStudio.Web.CodeGenerators.Mvc had to be updated manually as well.



标签: c# .net-core