dotnet new

by Rok Bermež 15. June 2016 13:12
Ena izmed opcij novega dotnet orodja za orodno vrstico je tudi 'new' in nam omogoča inicializirati nov .Net projekt. V osnovi nam ponuja dodatne –t kot tip in –l kot jezik dodatne možnosti ter seveda privzeto prazno, ki bo generirala 'Hello World' konzolno aplikacijo, ki jo lahko odpremo s katerimkoli urejevalnikom besedil ali pa kar takoj prevedemo in poženemo: D:\Pika>dotnet new Created new C# project in D:\Pika. D:\Pika>dotnet restore log : Restoring packages for D:\Pika\project.json... log : Writing lock file to disk. Path: D:\Pika\project.lock.json log : D:\Pika\project.json log : Restore completed in 1612ms. D:\Pika>dotnet run Project Pika (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing Compiling Pika for .NETCoreApp,Version=v1.0 Compilation succeeded. 0 Warning(s) 0 Error(s) Time elapsed 00:00:01.3401987 Hello World! Kot smo že omenili, lahko z -l zamenjamo jezik in z "dotnet new -l F#" naredimo namesto C# raje F# konzolno aplikacijo: D:\Pika>dotnet new -l F# Created new F# project in D:\Pika. D:\Pika>type Program.fs ´╗┐// Learn more about F# at http://fsharp.org open System [<EntryPoint>] let main argv = printfn "Hello World!" printfn "%A" argv 0 // return an integer exit code D:\Pika> Z –t izbiramo tip želenega projekta, tako na primer "dotnet new -t lib" hitro naredi novo knjižnico za enim Class1 razredom in prazno Empty metodo. Samo po sebi ne najbolj koristno, vendar vseeno v »dobro je vedeti« kategoriji. Prav tako lahko z "dotnet new -t xunittest" naredimo nov testni projekt, ki pa ga tokrat po "dotnet restore" pokličemo z "dotnet test": D:\Pika>dotnet new -t xunittest Created new C# project in D:\Pika. D:\Pika>dotnet restore log : Restoring packages for D:\Pika\project.json... warn : Dependency specified was dotnet-test-xunit (>= 1.0.0-rc2-192208-24) but ended up with dotnet-test-xunit 1.0.0-rc2-build10015. log : Writing lock file to disk. Path: D:\Pika\project.lock.json log : D:\Pika\project.json log : Restore completed in 2122ms. D:\Pika>dotnet test Project Pika (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing Compiling Pika for .NETCoreApp,Version=v1.0 D:\Pika\project.json(9,46): warning NU1007: Dependency specified was dotnet-test-xunit >= 1.0.0-rc2-192208-24 but ended up with dotnet-test-xunit 1.0.0-rc2-build10015. Compilation succeeded. 1 Warning(s) 0 Error(s) Time elapsed 00:00:01.4732457 xUnit.net .NET CLI test runner (64-bit win10-x64) Discovering: Pika Discovered: Pika Starting: Pika Finished: Pika === TEST EXECUTION SUMMARY === Pika Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0,184s SUMMARY: Total: 1 targets, Passed: 1, Failed: 0. Imamo tudi ASP.NET Core Hello World, do katerega pridemo s pomočjo ukaza "dotnet new -t Web.", ki nam naredi lep in enostaven začetni primer ASP.NET Core aplikacije, s primeri uporabe tehnologij kot so bower, gulp in npm. Alternativno lahko ustvarjamo ASP.NET Core projekte tudi s pomočjo precej močnejšega Yeoman Asp.Net generatorja: Vsi ti generatorji delujejo na Windows , Mac in Linux operacijskih sistemih, tako da bomo kmalu lahko 'vse' kar nam ponudi Visual studio v "File | New Project " menuju, lahko naredili preko orodne vrstice, tudi v konkurenčnih svetovih.

Tags:

.Net | c# | mvc | Web | Visual Studio

Manualy Submiting Unobtrusive MVC 3 Ajax Form

by Rok Bermež 21. April 2011 14:21
If you want to submit Ajax.BeginForm created ajax form a simple this.form.submit() wont work. Well to be exact it will, but not as it was intended. In order to make it work like expected, we can do it like this:   Html.DropDownList("selPredavanja",ViewBag.Lectures as SelectList,new { onchange = "Sys.Mvc.AsyncForm.handleSubmit( this.form, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'lectureData' });"})

Tags:

ASP.NET | mvc | Web

ASP.NET MVC 3 AJAX REDIRECT RESULT

by Rok Bermež 5. April 2011 14:31
From time to time, we need to selectively redirect the browser to another location as a result of an AJAX action. Just returning RedirectResult won’t do the trick (even if we are used to similar functionality in ASP.NET AJAX in combination with WebForms ). Here is a very simple RedirectResult thet will be appropriate in those scenarios: public class AjaxRedirectResult : RedirectResult { public AjaxRedirectResult(string url): base(url){} public override void ExecuteResult(ControllerContext context) { if (context.RequestContext.HttpContext.Request.IsAjaxRequest()) { JavaScriptResult result = new JavaScriptResult() { Script = String.Format("window.location='{0}';", UrlHelper.GenerateContentUrl(Url, context.HttpContext)) }; result.ExecuteResult(context); } else base.ExecuteResult(context); } }

Tags:

.Net | c# | ASP.NET | mvc | Web

MVC3 Windows Azure Deployment

by Rok Bermež 14. January 2011 12:12
For RTM version of MVC 3 make sure the deployment contains following dlls: Microsoft.Web.Infrastructure System.Web.Helpers System.Web.Mvc System.Web.Razor System.Web.WebPages System.Web.WebPages.Deployment System.Web.WebPages.Razor  

Tags:

ASP.NET | Azure | mvc

MultipleGenericBindingGenerator for Ninject.Extensions.Conventions

by Rok Bermež 10. January 2011 17:55
Ninject.Extensions.Conventions provides convention based binding for Ninject modeled after the StructureMap 2.5 AssemblyScanner by Jeremy Miller. When StructureMap users can use something like: Scan(scanner => { scanner.AssembliesFromApplicationBaseDirectory(assembly => assembly.FullName.StartsWith("Ntk.Infrastructure.")); scanner.ConnectImplementationsToTypesClosing(typeof (IMessageHandler <,>)); scanner.ConnectImplementationsToTypesClosing(typeof (IMessageHandler <>)); }); Ninject.Extensions.Conventions using GenericBindingGenerator can not: kernel.Scan(scanner => { scanner.FromAssembliesMatching( "Ntk.Infrastructure.*.dll" ); scanner.BindWith(new GenericBindingGenerator(typeof(IMessageHandler<>))); scanner.BindWith(new GenericBindingGenerator(typeof(IMessageHandler<,>))); scanner.InTransientScope(); }); So slightly modified version of GenericBindingGenerator called MultipleGenericBindingGenerator comes to the rescue: kernel.Scan(scanner => { scanner.FromAssembliesMatching("Ntk.Infrastructure.*.dll"); scanner.BindWith(new MultipleGenericBindingGenerator(typeof(IMessageHandler<>),typeof(IMessageHandler<,>))); scanner.InTransientScope(); }); If anyone needs anything like this, here is the code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Ninject; using Ninject.Activation; using Ninject.Extensions.Conventions; namespace TestProj{ public class MultipleGenericBindingGenerator : IBindingGenerator { private static readonly Type TypeOfObject = typeof (object); private readonly Type[] _contractTypes; /// <summary> /// Initializes a new instance of the <see cref="MultipleGenericBindingGenerator"/> class. /// </summary> /// <param name="contractTypes">Types of the contract.</param> public MultipleGenericBindingGenerator(params Type[] contractTypes) { foreach (var type in contractTypes) { if (!(type.IsGenericType || type.ContainsGenericParameters)) { throw new ArgumentException(String.Format("The contract must be an open generic type ({0}).",type.Name), "contractTypes"); } } _contractTypes = contractTypes; } #region Implementation of IBindingGenerator /// <summary> /// Processes the specified type creating kernel bindings. /// </summary> /// <param name="type">The type to process.</param> /// <param name="scopeCallback">the scope callback.</param> /// <param name="kernel">The kernel to configure.</param> public void Process( Type type, Func<IContext, object> scopeCallback, IKernel kernel ) { Type interfaceType = ResolveClosingInterface( type ); if ( interfaceType != null ) { kernel.Bind( interfaceType ).To( type ).InScope( scopeCallback ); } } #endregion /// <summary> /// Resolves the closing interface. /// </summary> /// <param name="targetType">Type of the target.</param> /// <returns></returns> public Type ResolveClosingInterface( Type targetType ) { if ( targetType.IsInterface || targetType.IsAbstract ) { return null; } do { Type[] interfaces = targetType.GetInterfaces(); foreach ( Type @interface in interfaces ) { if ( !@interface.IsGenericType ) { continue; } if (_contractTypes.Contains(@interface.GetGenericTypeDefinition())) { return @interface; } } targetType = targetType.BaseType; } while ( targetType != TypeOfObject ); return null; } } }

Tags:

.Net | c# | ASP.NET | mvc | Web

Calendar

<<  May 2017  >>
MonTueWedThuFriSatSun
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Page List

Month List