I have a project based on ASP.NET Core 1.0. I can build and run locally without any problems, but if I try to publish the project to Azure using the publish mechanism in Visual Studio 2015 (even if I try to publish locally to a folder in file system or using FTP) it fails unexpectedly without giving me any concrete message. If I run preview I always get this log:
The "Publish" task failed unexpectedly.
System.Exception:
Publishing Project.Web for .NETFramework,Version=v4.5.2/win7-x64
at Microsoft.DotNet.Tasks.Publish.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
If I try to publish ignoring this error or if I do not try to get the preview I get this:
1>------ Publish started: Project: Kunato.Web, Configuration: Debug Any CPU ------
rmdir /S /Q "C:\Users\thimo\AppData\Local\Temp\PublishTemp\Kunato.Web54\"
Environment variables:
DOTNET_CONFIGURE_AZURE=1
Path=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "C:\Code\Git\Web_KuNaTo\src\Kunato.Web" --framework net452 --output "C:\Users\thimo\AppData\Local\Temp\PublishTemp\Kunato.Web54" --configuration Debug --no-build
Publishing Kunato.Web for .NETFramework,Version=v4.5.2/win7-x64
1>Publish failed due to build errors. Check the error list for more details.
========== Build: 0 succeeded, 0 failed, 7 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
If I the do as requested and look at the error list, there is no error and everything looks good. Are there any other log files or anything to check where the problem might be?
project.json
{
"userSecretsId": "aspnet-Kunato.Web-753ff034-0ada-4809-84a8-a4f157c4ea43",
"dependencies": {
"Kunato.Common": "1.0.0-*",
"Kunato.Core": "1.0.0-*",
"Kunato.DataAccess": "1.0.0-*",
"Kunato.Edi": "1.0.0-*",
"Kunato.Entities": "1.0.0-*",
"Kunato.Localization": "1.0.0-*",
"ediFabric.Framework": "6.7.0",
"LumenWorksCsvReader": "3.9.0",
"Sendgrid": "6.3.4",
"StackExchange.Redis": "1.1.0-alpha2",
"StackExchange.Redis.StrongName": "1.1.0-alpha2",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0",
"Microsoft.AspNetCore.Authentication.Google": "1.0.0",
"Microsoft.AspNetCore.Authentication.MicrosoftAccount": "1.0.0",
"Microsoft.AspNetCore.Authentication.Twitter": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.AspNetCore.Cors": "1.0.0",
"Microsoft.AspNetCore.Session": "1.0.0",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.Caching.Redis": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"net452": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Kunato.Web.Services;
using Kunato.DataAccess;
using Kunato.Entities.Core;
using Kunato.Web.Helpers;
using System.Globalization;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Options;
using Kunato.DataAccess.Data;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Kunato.Web
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Application Insights data collection services to the services container.
services.AddApplicationInsightsTelemetry(Configuration);
// Add framework services.
services.AddDbContext<KunatoDatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Kunato.Web")));
services.AddIdentity<KunatoUser, KunatoRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 4;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#-.";
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<KunatoDatabaseContext>()
.AddDefaultTokenProviders();
// Add session
services.AddSession(options =>
{
options.CookieName = ".kunato.Session";
options.IdleTimeout = TimeSpan.FromMinutes(30);
});
// Add localization
services.AddLocalization();
// Register Version service
services.AddSingleton<IDeploymentEnvironment, DeploymentEnvironment>();
// Add localization to the request pipeline
var dtf = new DateTimeFormatInfo
{
ShortDatePattern = "dd.MM.yyyy",
LongDatePattern = "dd.MM.yyyy HH:mm",
ShortTimePattern = "HH:mm",
LongTimePattern = "HH:mm"
};
var nf = new NumberFormatInfo
{
CurrencyDecimalSeparator = ",",
CurrencyGroupSeparator = ".",
NumberDecimalSeparator = ",",
NumberGroupSeparator = ".",
NumberDecimalDigits = 3
};
// Add MVC services to the services container.
services.AddMvc().AddJsonOptions(options =>
{
// handle loops correctly
options.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
// use standard name conversion of properties
options.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();
// include $id property in the output
options.SerializerSettings.PreserveReferencesHandling =
PreserveReferencesHandling.Objects;
})
.AddViewLocalization()
.AddDataAnnotationsLocalization();
// Register Filters
services.AddScoped<LanguageActionFilter>();
services.Configure<RequestLocalizationOptions>(
options =>
{
var supportedCultures = new List<CultureInfo>
{
//new CultureInfo("en-US") { DateTimeFormat = dtf },
//new CultureInfo("en") { DateTimeFormat = dtf },
new CultureInfo("de-DE") { DateTimeFormat = dtf, NumberFormat = nf },
new CultureInfo("de") { DateTimeFormat = dtf, NumberFormat = nf }
//new CultureInfo("en-US"),
//new CultureInfo("en"),
//new CultureInfo("de-DE"),
//new CultureInfo("de")
};
options.DefaultRequestCulture = new RequestCulture(culture: "de-DE", uiCulture: "de-DE");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
// Add application settings from config
services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
// Register KunatoBaseData
//services.AddTransient<KunatoBaseData>();
//services.AddTransient<KunatoSampleData>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Add Application Insights to the request pipeline to track HTTP request telemetry data.
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<KunatoDatabaseContext>().Database.Migrate();
// Seeding the basic data to the database
var kunatoBaseData = app.ApplicationServices.GetService<KunatoBaseData>();
await kunatoBaseData.InitializeDataAsync();
// Seeding sample data to the database
//var kunatoSampleData = app.ApplicationServices.GetService<KunatoSampleData>();
//await kunatoSampleData.InitializeDataAsync();
}
}
catch { }
app.UseStaticFiles();
app.UseIdentity();
// Add session
app.UseSession();
// Add localization
var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(locOptions.Value);
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Related
I have Asp.Net core (Framework 4.6.1) solution with the following structure:
API sln
|-- WebApi.Project_1
|-- Project_2 (Core library, referencing Framework 4.6.1)
references Project_4 (Core Library, referencing Framework 4.6.1)
|-- Project_3 (Core library, referencing Framework 4.6.1)
references Project_4 (Core Library, referencing Framework 4.6.1)
See the "sanitized" project.json files below.
Some notes:
• there is a number of classic (4.6.1 .net) libraries added to the solution but not referenced yet by any other core projects.
• I created the core libraries and manually referenced .net framework 4.6.1 from their json files
•they use x86 platform, specified in project.json -> buildOptions
Everything is built and run OK by using VisualStudio 2015 (either on my local machine or locally on the same build agent server)
The solution build fails when it is built in CI build by TFS 2015 build engine with the following error:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(265,5): Error: D:\tfsAgent_work\folder\folder\Project_2\error CS0006: metadata file '\folder\folder\bin\debug\net461\Project_4.dll' could not be found"
Same error, but for Project_3, referencing Project_4 as well.
By looking at the build log I see that Project_4 is built after Projects 2 and 3, thus the file is not there yet.
I tried different options:
•adding the references in project.json
•using Project references
•Solution properties -> Project dependencies...
•manually reorder the projects in API.sln file.
No difference.
**WebApi_Project_1.json:**
{
"dependencies": {
"Project_2": "1.0.0-*",
"Project_3": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"System.Net.Http": "4.1.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"platform": "x86",
"copyToOutput": {
"include": [
"Folder/Folder/Folder/*.xsd",
"Folder/Folder/Folder/*.xml"
]
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder % publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
**Project_2.json**
{
"dependencies": {
"Project_4": "1.0.0.0"
},
"buildOptions": {"platform": "x86"},
"frameworks": {
"net461": {}
}
}
**Project_3.json**
{
"buildOptions": { "platform": "x86" },
"dependencies": {
"Project_4": "1.0.0.0"
},
"frameworks": {
"net461": {
"frameworkAssemblies": {
"System.Xml": "4.0.0.0"
}
}
}
}
**Project_4.json**
{
"version": "1.0.0.0",
"buildOptions": { "platform": "x86" },
"frameworks": {
"net461": {}
}
}
I have built a relatively simple ASP.Net Core web application that uses Angular 2 & bootstrap for the front end and WebApi as the back end.
I am able to build and run my application locally (to IIS Express) and it works just fine, however, when I attempt to use the Build -> Publish menu I encounter a NullReferenceExceptionError that is terrible unhelpful. Here is the output when I run Publish:
1>------ Publish started: Project: MyProject, Configuration: Release Any CPU ------
Connecting to C:\ProjectDir\MyProject\./bin/Release/PublishTest...
rmdir /S /Q "C:\Users\UserName\AppData\Local\Temp\PublishTemp\MyProject86\"
Environment variables:
Path=%PATH%;.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "C:\ProjectDir\MyProject" --framework net452 --output "C:\Users\UserName\AppData\Local\Temp\PublishTemp\MyProject86" --configuration Release --no-build
Publishing MyProject for .NETFramework,Version=v4.5.2/win7-x64
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(149,5): Error : Object reference not set to an instance of an object.
1>Publish failed due to build errors. Check the error list for more details.
========== Build: 0 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
I have attempted to do a FileSystem publish to both a directory on a server running IIS as well as just a local directory, and I get the same output in both of these instances.
I have cleaned my solution, rebuilt, and restarted Visual Studio just in case it had been in a bad state. I've created a few different publish profiles just to make certain that something wasn't misconfigured with that (some of them were created after the restart of VS2015, as well).
In addition I made sure to update VS2015 after I started having this problem, and I am now running version 14.0.25425.01 Update 3. I also have the latest web tools installed.
Here is my project.json file:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net452": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
],
"dependencies": {
"aDependency": {
"target": "project"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
I've been searching for anyone else having this issue and I believe I found one or two other places where this seems to have been encountered but I haven't found anyone that has replied with a solution or even a theory to what is happening exactly. Any help, theories, or leads would be appreciated.
Thanks for your time.
EDIT: As suggested in the comments I created a new ASP.NET Core application since 1.0.0 was released and took a look at the differences. It worked and I feel silly for missing this, anyway, for anyone else who runs into this (albeit temporally limited) issue, here's the fixed project.json file:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
],
"dependencies": {
"aDependency": {
"target": "project"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
I think you should update your app from RC2 to 1.0.0 and you may want to create a new web app with 1.0.0 and the latest tooling/vs project templates from dot.net then compare the project.json and startup code to your existing app and update the existing app
Using the following in startup
app.UseWebSockets();
app.Map("/signalr", signalrApp =>
{
signalrApp.UseKatana(config =>
{
config.RunSignalR(new HubConfiguration
{
EnableDetailedErrors = true,
});
});
});
and a simple hub
public class MyHubBroadcaster : Hub
{
public void Test()
{
Clients.All.addContosoChatMessageToPage("a", "b");
}
}
and starting signalr
var connection = $.hubConnection();
connection.logging = true;
var contosoChatHubProxy = connection.createHubProxy('myHubBroadcaster');
contosoChatHubProxy.on('addContosoChatMessageToPage', function (userName, message) {
console.log(userName + ' ' + message);
});
console.log(connection);
var promise = connection.start();
promise.done(function () {
console.log('Now connected, connection ID=' + connection.id);
setInterval(() => {
contosoChatHubProxy.invoke('test').done((d) => console.log(d));
}, 10000);
})
promise.fail(function () { console.log('Could not connect'); });
negotiantion returns TryWebSockets = false
Am i missing something or should this work?
main.cs
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
project.json
{
"dependencies": {
"Microsoft.AspNet.SignalR.Core": "2.2.1",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.ServiceFabric": "5.1.163",
"Microsoft.ServiceFabric.Data": "2.1.163",
"Microsoft.ServiceFabric.Services": "2.1.163",
"S-Innovations.ServiceFabric.Gateway.RegistrationMiddleware.AspNetCore": "1.0.1-pre-2016082001",
"Microsoft.AspNetCore.Owin": "1.0.0",
"AspNet.Hosting.Katana.Extensions": "1.0.0-alpha3-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.WebSockets.Server": "0.1.0"
},
"tools": {
},
"frameworks": {
"net452": {
"frameworkAssemblies": {
"System.Numerics": "4.0.0.0"
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
}
}
I'm trying to use PostgreSQL for the first time and having a little trouble getting it to build without errors unless I lock into RC2 packages which is fine. After locking into the RC2 packages, I have one error that I can't seem to shake that I could use help troubleshooting:
ERROR
Startup.cs(22,18): error CS1061: 'IServiceCollection' does not contain a definition for 'AddNpgsql' and no extension method 'AddNpgsql' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
PROJECT.JSON
{
"buildOptions": {
"preserveCompilationContext": true,
"emitEntryPoint": true,
"warningsAsErrors": true,
"debugType": "portable",
"copyToOutput": {
"include": [
"wwwroot",
"Views",
"config.json",
"web.config"
]
}
},
"dependencies": {
"AspNet.Security.OAuth.Introspection": "1.0.0-alpha1-final",
"AspNet.Security.OAuth.Validation": "1.0.0-alpha1-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.Cors": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Commands": "1.0.0-rc2-*",
"Microsoft.EntityFrameworkCore.Relational": "1.0.0-rc2-final",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0-*",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
"OpenIddict.Core": "1.0.0-*",
"OpenIddict.EF": "1.0.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
}
},
"imports": [
"dnxcore50",
"portable-net451+win8"
]
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+wp80+win8+wpa81+dnxcore50"
}
},
"scripts": {
"postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"config.json",
"web.config"
]
}
}
STARTUP.CS (Partial)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<ApplicationContext>(options =>
options.UseNpgsql("Host=localhost;Username=dev;Password=dev;Database=tesdb"));
services.AddIdentity<tbl_ApplicationUser, tbl_ApplicationRole>()
.AddEntityFrameworkStores<ApplicationContext>()
.AddUserStore<CustomStore>()
.AddDefaultTokenProviders()
.AddOpenIddictCore<tbl_Application>
(conf => conf.UseEntityFramework());
services.AddAuthorization(options => {
options.AddPolicy("Default", builder => {
builder.RequireAuthenticatedUser();
builder.RequireActiveUser();
});
options.DefaultPolicy = options.GetPolicy("Default");
});
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
services.AddTransient<IUtilityService, UtilityService>();
services.AddScoped<ICommonRepository, CommonRepository>();
}
In EF Core 1.1 you need to use this code:
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddEntityFrameworkNpgsql();
}
}
and
public class DatabaseClass : DbContext
{
//...
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("my connection string");
}
}
The RC2 driver replaced AddNpgsql with AddEntityFrameworkNpgsql, so
replace this code block:
services.AddEntityFramework()
.AddNpgsql()
.AddDbContext<ApplicationContext>(options =>
options.UseNpgsql("Host=localhost;Username=dev;Password=dev;Database=tesdb"));
With this one:
services.AddEntityFrameworkNpgsql()
.AddDbContext<ApplicationContext>(options =>
options.UseNpgsql("Host=localhost;Username=dev;Password=dev;Database=tesdb"));
So it sounds like a trivial task, I just want to use common code from my class library in both my web api and webapp but I am unable to reference the class library from my webapp projects, so I made a clean project to test it out.
I have 3 projects:ClassLib1, ClassLib2, WebApp
I am able to reference ClassLib1 From ClassLib2 but I cannot referance either Class librarys from the webapp project
Here are my project.json's
ClassLib1
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
},
"frameworks": {
"netstandard1.5": {
}
}
}
ClassLib2 is exactly the same as ClassLib1
Web App
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"ClassLib1": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
SS showing using ClassLib1 in ClassLib2 successfully
SS showing error in webapp when trying to use ClassLib1
The error when moused over is `cannot resolve symbol 'ClassFromLib1'
Edit: I just noticed that if I change the web app to use netstandard1.5 from netcoreapp1.0 I can then referance code between the projects.
Should I do this? are there any downside by changing the framework in targeting?
So I figured out that the issue I was having was with Resharper. It was making the text red and giving me the errors, it did actually build and work fine but I just didn't see past the red text.