프로젝트 간에 함수 호출
Visual Studio에서 두 개의 프로젝트를 추가하고 프로젝트 간에 함수 호출을 가능하게 하려면, 다음 단계를 따라야 합니다: ProjectA에서 함수 호출: 이 단계를 따르면 Visual Studio에서 두 개의 프로젝트 간에 함수 호출이 가능해집니다.
Visual Studio에서 두 개의 프로젝트를 추가하고 프로젝트 간에 함수 호출을 가능하게 하려면, 다음 단계를 따라야 합니다: ProjectA에서 함수 호출: 이 단계를 따르면 Visual Studio에서 두 개의 프로젝트 간에 함수 호출이 가능해집니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Mvc; using System.Net.Http.Headers; namespace StartupBasic { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.UseMvc(routes => routes.MapRoute( name: "default_route", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }) ); } } public class HomeController : Controller { IHostingEnvironment _env; public HomeController(IHostingEnvironment env) { _env = env; } public ActionResult Index() { return new ContentResult { Content = "<html><body><h1>Download File</h1>Download a copy of <a href=\"/home/hegel\">Hegel (pdf)</a></body></html>", ContentType = "text/html" }; } //public FileStreamResult Hegel() //{ // var pathToIdeas = System.IO.Path.Combine(_env.WebRootPath, "hegel.pdf"); // //This is a contrite example to demonstrate returning a stream. If you have a physical file on disk, just use PhySicalFileResult that takes a path. // return new FileStreamResult(System.IO.File.OpenRead(pathToIdeas), "application/pdf") // { // FileDownloadName = "hegel.pdf" // }; //} public PhysicalFileResult Hegel() { var pathToIdeas = System.IO.Path.Combine(_env.WebRootPath, "hegel.pdf"); return new PhysicalFileResult(pathToIdeas, "application/pdf"); } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : Download File Download a copy of Hegel (pdf)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Mvc; namespace MvcRouting { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.UseMvc(); } } [Route("[controller]/[action]")] public class HomeController : Controller { [HttpGet("/")] [HttpGet("")] public ActionResult Index() { return new ContentResult { Content = @" <html><body> <h1>[controller] and [action] replacement tokens examples</h1> <ul> <li><a href=""/"">/</a></li> <li><a href=""/home/index"">/home/index</a></li> <li><a href=""/home/about"">/home/about</a></li> <li><a href=""/about"">/about</a></li> </ul> </body></html>", ContentType = "text/html" }; } public ActionResult About() { return new ContentResult { Content = @" <html><body> <b>About Page</b </body></html>", ContentType = "text/html" }; } [HttpGet("/about")] public ActionResult About2() { return new ContentResult { Content = @" <html><body> <b>About Page 2</b </body></html>", ContentType = "text/html" }; } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : [controller] replacement token examples •/ •/home/ •/home/about •/about
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Mvc; namespace MvcRouting { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.UseMvc(); } } [Route("[controller]")] public class HomeController : Controller { [HttpGet("/")] [HttpGet("")] //You have to do this otherwise /Home/Index won't work public ActionResult Index() { return new ContentResult { Content = @" <html><body> <h1>[controller] replacement token examples</h1> <ul> <li><a href=""/"">/</a></li> <li><a href=""/home/"">/home/</a></li> <li><a href=""/home/about"">/home/about</a></li> <li><a href=""/about"">/about</a></li> </ul> </body></html>", ContentType = "text/html" }; } [HttpGet("about")] public ActionResult About() { return new ContentResult { Content = @" <html><body> <b>About Page</b </body></html>", ContentType = "text/html" }; } [HttpGet("/about")] public ActionResult About2() { return new ContentResult { Content = @" <html><body> <b>About Page 2</b </body></html>", ContentType = "text/html" }; } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : [controller] replacement token examples •/ •/home/ •/home/about •/about
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Mvc; namespace MvcRouting { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.UseMvc(routes => { routes.MapRoute( name: "home", template: "/", defaults: new { controller = "Home", action = "Index" }); routes.MapRoute( name: "default", template: "{controller}/{action}", defaults: new { controller = "Home", action = "Index" }); }); } } public class HomeController : Controller { public ActionResult Index() { return new ContentResult { Content = @" <html><body> <b>Hello World</b> <br/><br/> The following links call the same controller and action. <ul> <li><a href=""/"">/</a></li> <li><a href=""/Home"">/Home</a></li> <li><a href=""/Home/index"">/Home/index</a></li> </ul> </body></html>", ContentType = "text/html" }; } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : Hello World The following links call the same controller and action. •/ •/home •/home/index 동일 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
namespace MvcRouting { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.UseMvc(); } } [Route("")] [Route("Home")] [Route("Home/Index")] public class HomeController : Controller { public ActionResult Index() { return new ContentResult { Content = @" <html><body> <b>Hello World</b> <br/><br/> The following links call the same controller and action. <ul> <li><a href=""/"">/</a></li> <li><a href=""/home"">/home</a></li> <li><a href=""/home/index"">/home/index</a></li> </ul> </body></html>", ContentType = "text/html" }; } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Mvc; namespace StartupBasic { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { //These are three services available at constructor } public void ConfigureServices(IServiceCollection services) { services.AddMvcCore(). SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.UseMvc(routes => routes.MapRoute( name: "default_route", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }) ); } } public class HomeController : Controller { public ActionResult Index() { return new ContentResult { Content = "<html><body><b>Hello World</b></body></html>", ContentType = "text/html" }; } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : Hello World
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Mvc.Formatters; namespace MvcOutputXml { public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(config => { config.OutputFormatters.Add(new XmlSerializerOutputFormatter()); }); } public void Configure(IApplicationBuilder app) { app.UseMvc(); } } public class Greeting { public bool Hello { get; set; } public bool World { get; set; } } public class HomeController : Controller { [HttpGet("")] public IActionResult Index() { var h = new Greeting { Hello = true, World = true }; Response.ContentType = "text/xml"; return Ok(h); } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과
1 2 3 4 5 6 7 |
<?xml version="1.0"?> <Greeting xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Hello>true</Hello> <World>true</World> </Greeting> |
1. 사이트 https://visualstudio.microsoft.com/ko/downloads/ 2. 다운로드 및 설치 3. 설치중 4. Net core 프로그램 선택 후 설치 5. 설치중
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
using Microsoft.AspNetCore.Hosting; //IWebHostBuilder using Microsoft.AspNetCore.Builder; //IApplicationBuilder using Microsoft.AspNetCore.Http; //WriteAsync using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using System.Collections.Generic; using Microsoft.AspNetCore.WebUtilities; //QueryHelpers namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger) { //These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { //This is the only service available at ConfigureServices } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { app.Run(async context => { var queryString = QueryHelpers.ParseQuery(context.Request.QueryString.ToString()); var output = ""; foreach (var qs in queryString) { output += qs.Key + " = " + qs.Value + "<br/>"; } await context.Response.WriteAsync($@"<html> <body> <h1>Parsing Raw Query String</h1> <ul> <li><a href=""?name=anne"">?name=anne</a></li> <li><a href=""?name=anne&name=mishkind"">?name=anne&name=mishkind</a></li> <li><a href=""?age=25&smart=true"">?age=25&smart=true</a></li> <li><a href=""?country=zambia&country=senegal&country="">?country=zambia&country=senegal&country=</a></li> <li><a href=""?"">?</a></li> <br /><br /> <strong>Query String</strong><br/> {output} </ul> </body> </html>"); }); } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : Parsing Raw Query String •?name=anne •?name=anne&name=mishkind •?age=25&smart=true •?country=zambia&country=senegal&country= •? Query String name = anne,mishkind
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using Microsoft.AspNetCore.Hosting; //IWebHostBuilder using Microsoft.AspNetCore.Builder; //IApplicationBuilder using Microsoft.AspNetCore.Http; //WriteAsync using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore; using Microsoft.Extensions.Configuration; using System.Collections.Generic; using Microsoft.AspNetCore.WebUtilities; //QueryHelpers namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger) { //These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { //This is the only service available at ConfigureServices } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger, IConfiguration configuration) { var arguments = new Dictionary<string, string>() { {"greetings", "hello-world"}, {"origin", "cairo"} }; var path = QueryHelpers.AddQueryString("/greet", arguments); app.Run(context => { return context.Response.WriteAsync($"{path}"); }); } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseEnvironment("Development"); } } |
결과 : /greet?greetings=hello-world&origin=cairo