我试图在我的测试解决方案中生成脚手架组件。我右键单击我的项目,然后单击"添加脚手架项目"然后我用实体框架"中的动作选择" API控制器。在那里我选择我的模型类和上下文,当我点击Add时,它会抛出以下错误:
错误 运行所选代码生成器时出错:'未处理异常:System.TypeLoadException:无法加载类型' Microsoft.VisualStudio.Web.Codegeneration.Core,Version = 1.1.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60',在Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Main(String [] args)'
我确信这是由解决方案的依赖性问题引起的。到目前为止,我已尝试包含Microsoft.VisualStudio.Web.CodeGeneration.Core库但未解决问题。
这些是我项目的依赖项:
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.1"
},
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.1.0",
"type": "build"
},
"Microsoft.AspNetCore.Authentication.Cookies": "1.1.1",
"Microsoft.AspNetCore.Diagnostics": "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.Configuration.EnvironmentVariables": "1.1.1",
"Microsoft.Extensions.Configuration.Json": "1.1.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.1",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.1",
"Microsoft.Extensions.Configuration.UserSecrets": "1.1.1",
"Microsoft.AspNetCore.Routing": "1.1.1",
"Microsoft.AspNetCore.StaticFiles": "1.1.1",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
"Microsoft.AspNetCore.Mvc": "1.1.2",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.1",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.1.0-preview4-final",
"type": "build"
},
"Microsoft.EntityFrameworkCore": "1.1.1",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.1.0",
"type": "build"
},
"Pomelo.EntityFrameworkCore.MySql": "1.1.1-prerelease-10020",
"Pomelo.EntityFrameworkCore.MySql.Design": "1.1.1-prerelease-10020",
"Microsoft.VisualStudio.Web.CodeGeneration.Core": "1.1.0"
},
"tools": {
"BundlerMinifier.Core": "2.4.337",
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4",
"Microsoft.Extensions.SecretManager.Tools": "1.1.0-preview4-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.1.0-preview4-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
提前感谢您的帮助。
答案 0 :(得分:0)
由于依赖项中的错误版本和平台的不兼容代码生成器导致的问题。
打开/转换项目到VS2017社区并与VS2017的空白新对比显示问题。我强迫VS2015使用.Net Core 1.1.1和无法使用的代码生成器版本。
错误:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.1-prerelease-10020" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.1-prerelease-10020" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Core" Version="1.1.0" />
右:
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.1-prerelease-10020" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.1-prerelease-10020" />