Gulp VS2015 .Net5 - asp.net

Im trying to learn Gulp and have been unable to successfully run tasks via the Task Run Explorer. No tasks appear and the Explorer shows the error: Failed to load, see output window for more information. When checking the output window it appears that it cant find my project.json.
Failed to run "F:\Projects\NewInventory\src\NewInventory\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
Error: Cannot find module ' ./project.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (F:\Projects\NewInventory\src\NewInventory\gulpfile.js:12:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Failed to run "F:\Projects\NewInventory\src\NewInventory\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
Error: Cannot find module ' ./project.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (F:\Projects\NewInventory\src\NewInventory\gulpfile.js:12:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
However, I also created a new .Net5 web application from scratch and compared with my current project to ensure that the project.json was in the correct directory location.
My project.json is as follows:
"webroot": "wwwroot",
"userSecretsId": "aspnet5-NewInventory-f5a8bab7-e95b-485b-97e9-9a072438b107",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Commands": "7.0.0-beta8",
"Microsoft.AspNet.Mvc": "6.0.0-beta8",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
"Microsoft.AspNet.Http.Features": "1.0.0-beta8",
"Microsoft.AspNet.Http.Abstractions": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta8",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta8",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta8",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta8",
"Microsoft.Framework.Configuration": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Binder": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta8",
"Microsoft.Framework.Logging": "1.0.0-beta8",
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta8",
"Microsoft.Framework.Logging.Debug": "1.0.0-beta8"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
},
"configurations": {
}
}
Package.json
{
"name": "ASP.NET",
"version": "0.0.0",
"devDependencies": {
"gulp": "3.8.11",
"gulp-concat": "2.5.2",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"gulp-jshint": "1.11.2",
"rimraf": "2.2.8",
"del": "2.0.2",
"gulp-bower": "0.0.10",
"npm-check-updates": "2.3.2"
}
}
Gulpfile.js
var gulp = require("gulp"),
rimraf = require("rimraf"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
uglify = require("gulp-uglify"),
project = require("./project.json");
var bower = require('gulp-bower');
var del = require('del');
var project = require(' ./project.json');
var lib = project.webroot + '/lib';
var paths = {
webroot: "./" + project.webroot + "/"
};
paths.js = paths.webroot + "js/**/*.js";
paths.minJs = paths.webroot + "js/**/*.min.js";
paths.css = paths.webroot + "css/**/*.css";
paths.minCss = paths.webroot + "css/**/*.min.css";
paths.concatJsDest = paths.webroot + "js/site.min.js";
paths.concatCssDest = paths.webroot + "css/site.min.css";
gulp.task('default', ['bower:install'], function () {
return;
});
gulp.task('bower:install', ['clean'], function () {
return bower({
directory: lib
});
});
gulp.task('clean', function (done) {
del(lib, done);
});
gulp.task("clean:js", function (cb) {
rimraf(paths.concatJsDest, cb);
});
gulp.task("clean:css", function (cb) {
rimraf(paths.concatCssDest, cb);
});
gulp.task("clean", ["clean:js", "clean:css"]);
gulp.task("min:js", function () {
gulp.src([paths.js, "!" + paths.minJs], { base: "." })
.pipe(concat(paths.concatJsDest))
.pipe(uglify())
.pipe(gulp.dest("."));
});
gulp.task("min:css", function () {
gulp.src([paths.css, "!" + paths.minCss])
.pipe(concat(paths.concatCssDest))
.pipe(cssmin())
.pipe(gulp.dest("."));
});
gulp.task("min", ["min:js", "min:css"]);

You can fix the error by removing the line
var project = require(' ./project.json');
The space at the beginning of the path literal means it is not pointing at project.json. There is a line before doing what you need it to do;
var gulp = require("gulp"),
rimraf = require("rimraf"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
uglify = require("gulp-uglify"),
project = require("./project.json"); <---- This is doing what you expected.

Related

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Framework.Runtime.ILibraryManager'

I have the following project.json file...
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta5",
"EntityFramework.SqlServer": "7.0.0-beta5",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands",
"gen": "Microsoft.Framework.CodeGeneration"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
I am trying now to do some MVC 6 Controller Scaffolding in command line but after executing the command:
dnx gen controller -name ClassController --dataContext
RegistrationDbContext --model Class
However, I am getting the following error message...
EDIT: This is the message that I am getting after installing Microsoft.Framework.CodeGeneration package (Install-Package Microsoft.Framework.CodeGeneration -Pre)
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Framework.Runtime.ILibraryManager' while attempting to activate 'Microsoft.Framework.CodeGeneration.DefaultCodeGeneratorAssemblyProvider'.
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.Framework.DependencyInjection.ActivatorUtilities.CreateInstance[T](IServiceProviderprovider, Object[] parameters)
at Microsoft.Framework.CodeGeneration.ServiceProvider.AddServiceWithDependencies[TService,TImplementation]()
at Microsoft.Framework.CodeGeneration.Program.AddCodeGenerationServices(ServiceProvider serviceProvider)
at Microsoft.Framework.CodeGeneration.Program..ctor(IServiceProvider serviceProvider)
Any pointers? How can I fix that?
In any case, this is my global.json too..
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta5",
"runtime": "clr",
"architecture": "x64"
}
}
Thanks!
In rc1-final, the namespaces have changed :
FROM: Microsoft.Framework.CodeGeneration
TO: Microsoft.Extensions.CodeGeneration
project.json
"dependencies": {
...
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
}
"commands": {
...
"gen": "Microsoft.Extensions.CodeGeneration"
}
To customize the MVC6 scaffolding templates, you will find them in the folder: C:\Users\{user}\.dnx\packages\Microsoft.Extensions.CodeGenerators.Mvc\1.0.0-rc1-final\Templates
Use dnx gen controller --help to get some help on the parameters

Adding reference to Class Library issue in ASP.NET 5 beta 7

I removed dnxcore50 from project.json and added an empty class library to solution. When I add reference to class library, project build correctly but when I want to publish project, I will get this error:
The expected lock file doesn't exist. Please run "dnu restore" to generate a new lock file
dnu restore command also not helps.
If i remove reference to class library, publish works fine.
project.json:
{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-AdsProject-e7d42575-2bc4-4316-881a-236435c407a1",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta7",
"EntityFramework.SqlServer": "7.0.0-beta7",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
"Microsoft.Framework.Logging": "1.0.0-beta7",
"Microsoft.Framework.Logging.Console": "1.0.0-beta7",
"Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"dependencies": {
"ClassLibrary": "1.0.0-*"
}
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}
Be sure you resolved all reference warnings and don't mix different beta versions.
Are both versions still in beta7 incl your visual studio??
Try upgrade to beta 8 all projects, dnvm,dnx and visual studio
See the home repro
I know this is a bit late. I had the exact same issue on beta 7 today. And only with custom libs added.
I got it fixed by going into the folder called "wrap" that gets created when you add your library. In there you'll find a project.json. Run a dnu restore on that folder in cmd.
Worked like a charm for me.

EF7: dnx ef command error "Value can not be Null"

When I use the command
dnx ef
the following error occurs:
C:\Users\Livio\OneDrive\Informatik\Websites\HomeNetwork\src\HomeNetwork.API>dnx ef
System.ArgumentNullException: Value cannot be null.
Parameter name: appEnv
at Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.Data.Entity.Commands.Program..ctor(IServiceProvider > serviceProvider, IApplicationEnvironment appEnv, ILibraryManager libraryManager, > IRuntimeEnvironment runtimeEnv)
I'm using dnvm 1.0.0-beta8 coreclr x86.
My project.json looks like this (in HomeNetwork.API)
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"EntityFramework.SqlServer": "7.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
I created this project without editing the code, expect adding the EF7 Dependency.
I'm using dnvm 1.0.0-beta8 coreclr x86.
Then, you should use the beta8 versions of the dependencies:
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta8",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta8",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Commands": "7.0.0-beta8"
}

ASP.Net5 Startup.cs ConfigurationBuilder [duplicate]

This question already has an answer here:
Specify the application base path in ConfigurationBuilder in beta8
(1 answer)
Closed 7 years ago.
Using VS 2015 with beta 8 of MVC, I receive the following error
"Severity Code Description Project File Line
Error CS1503 Argument 1: cannot convert from 'string' to 'Microsoft.Framework.Configuration.IConfigurationProvider' NewInventory.DNX Core 5.0 F:\Projects\NewInventory\src\NewInventory\Startup.cs 35
from this portion of my startup.cs:
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// This reads the configuration keys from the secret store.
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
When I hover over ConfigurationBuilder I can see its looking for'ConfigurationBuilder.ConfigurationBuilder(params IConfigurationProvider[] providers)'
How do I change the appEnv.ApplicationBasePath to an IConfigurationProvider array?
my project.json is:
{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-NewInventory-f5a8bab7-e95b-485b-97e9-9a072438b107",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.SqlServer":"7.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta8",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
"Microsoft.AspNet.Identity.EntityFramework":"3.0.0-beta8",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
"Microsoft.Framework.Configuration": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Binder": "1.0.0-beta8",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
"Microsoft.Framework.Logging": "1.0.0-beta5",
"Microsoft.Framework.Logging.Console": "1.0.0-beta5",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
},
"configurations": {
}
}
There is no more constructor of ConfigurationBuilder having appEnv.ApplicationBasePath as argument, but instead there is SetBasePath method.
So change your code to:
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

Generating code from an existing database EF7

I'm trying to generate code from my database but i get errors : System.AggregateException: One or more errors occurred. ---> Method not found
this is my project.json:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"EntityFramework.SqlServer": "7.0.0-beta8-15797",
"EntityFramework.Commands": "7.0.0-beta8-15797",
"EntityFramework.SqlServer.Design": "7.0.0-beta8-15797",
"Remotion.Linq": "2.0.0-rc-001"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
How do i Generating code from an existing database EF7
I'm using this command :
dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer
Thank you.
Upgrade all packages to be consistent. You have beta5 and beta 8 mixed. If you still experience errors, please check or file and issue to the appropriate repository. https://github.com/aspnet

Resources