@@ -213,23 +213,82 @@ In most cases, migrating requires you to add the following program.cs file to yo
213
213
214
214
# [ .NET 6 (isolated)] ( #tab/net6-isolated )
215
215
216
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="23-29":::
216
+ ``` csharp
217
+ using Microsoft .Extensions .Hosting ;
218
+
219
+ var host = new HostBuilder ()
220
+ .ConfigureFunctionsWebApplication ()
221
+ .ConfigureServices (services => {
222
+ services .AddApplicationInsightsTelemetryWorkerService ();
223
+ services .ConfigureFunctionsApplicationInsights ();
224
+ })
225
+ .Build ();
226
+
227
+ host .Run ();
228
+ ```
217
229
218
230
# [ .NET 6 (in-process)] ( #tab/net6-in-proc )
219
231
220
232
A program.cs file isn't required when running in-process.
221
233
222
234
# [ .NET 7] ( #tab/net7 )
223
235
224
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="23-29":::
236
+ ``` csharp
237
+ using Microsoft .Extensions .Hosting ;
238
+
239
+ var host = new HostBuilder ()
240
+ .ConfigureFunctionsWebApplication ()
241
+ .ConfigureServices (services => {
242
+ services .AddApplicationInsightsTelemetryWorkerService ();
243
+ services .ConfigureFunctionsApplicationInsights ();
244
+ })
245
+ .Build ();
246
+
247
+ host .Run ();
248
+ ```
225
249
226
250
# [ .NET Framework 4.8] ( #tab/netframework48 )
227
251
228
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="2-20":::
252
+ ``` csharp
253
+ using Microsoft .Extensions .Hosting ;
254
+ using Microsoft .Azure .Functions .Worker ;
255
+
256
+ namespace Company .FunctionApp
257
+ {
258
+ internal class Program
259
+ {
260
+ static void Main (string [] args )
261
+ {
262
+ FunctionsDebugger .Enable ();
263
+
264
+ var host = new HostBuilder ()
265
+ .ConfigureFunctionsWorkerDefaults ()
266
+ .ConfigureServices (services => {
267
+ services .AddApplicationInsightsTelemetryWorkerService ();
268
+ services .ConfigureFunctionsApplicationInsights ();
269
+ })
270
+ .Build ();
271
+ host .Run ();
272
+ }
273
+ }
274
+ }
275
+ ```
229
276
230
277
# [ .NET 8 Preview (isolated)] ( #tab/net8 )
231
278
232
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="23-29":::
279
+ ``` csharp
280
+ using Microsoft .Extensions .Hosting ;
281
+
282
+ var host = new HostBuilder ()
283
+ .ConfigureFunctionsWebApplication ()
284
+ .ConfigureServices (services => {
285
+ services .AddApplicationInsightsTelemetryWorkerService ();
286
+ services .ConfigureFunctionsApplicationInsights ();
287
+ })
288
+ .Build ();
289
+
290
+ host .Run ();
291
+ ```
233
292
234
293
---
235
294
@@ -408,23 +467,135 @@ In version 4.x, the HTTP trigger template looks like the following example:
408
467
409
468
# [ .NET 6 (isolated)] ( #tab/net6-isolated )
410
469
411
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/Templates/HttpTrigger-CSharp-Isolated/HttpTriggerCSharp.cs":::
470
+ ``` csharp
471
+ using Microsoft .AspNetCore .Http ;
472
+ using Microsoft .AspNetCore .Mvc ;
473
+ using Microsoft .Azure .Functions .Worker ;
474
+ using Microsoft .Extensions .Logging ;
475
+
476
+ namespace Company .Function
477
+ {
478
+ public class HttpTriggerCSharp
479
+ {
480
+ private readonly ILogger <HttpTriggerCSharp > _logger ;
481
+
482
+ public HttpTriggerCSharp (ILogger <HttpTriggerCSharp > logger )
483
+ {
484
+ _logger = logger ;
485
+ }
486
+
487
+ [Function (" HttpTriggerCSharp" )]
488
+ public IActionResult Run (
489
+ [HttpTrigger (AuthorizationLevel .Function , " get" )] HttpRequest req )
490
+ {
491
+ _logger .LogInformation (" C# HTTP trigger function processed a request." );
492
+
493
+ return new OkObjectResult ($" Welcome to Azure Functions, {req .Query [" name" ]}!" );
494
+ }
495
+ }
496
+ }
497
+ ```
412
498
413
499
# [ .NET 6 (in-process)] ( #tab/net6-in-proc )
414
500
415
501
:::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/Templates/HttpTrigger-CSharp/HttpTriggerCSharp.cs":::
416
502
417
503
# [ .NET 7] ( #tab/net7 )
418
504
419
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/Templates/HttpTrigger-CSharp-Isolated/HttpTriggerCSharp.cs":::
505
+ ``` csharp
506
+ using Microsoft .AspNetCore .Http ;
507
+ using Microsoft .AspNetCore .Mvc ;
508
+ using Microsoft .Azure .Functions .Worker ;
509
+ using Microsoft .Extensions .Logging ;
510
+
511
+ namespace Company .Function
512
+ {
513
+ public class HttpTriggerCSharp
514
+ {
515
+ private readonly ILogger <HttpTriggerCSharp > _logger ;
516
+
517
+ public HttpTriggerCSharp (ILogger <HttpTriggerCSharp > logger )
518
+ {
519
+ _logger = logger ;
520
+ }
521
+
522
+ [Function (" HttpTriggerCSharp" )]
523
+ public IActionResult Run (
524
+ [HttpTrigger (AuthorizationLevel .Function , " get" )] HttpRequest req )
525
+ {
526
+ _logger .LogInformation (" C# HTTP trigger function processed a request." );
527
+
528
+ return new OkObjectResult ($" Welcome to Azure Functions, {req .Query [" name" ]}!" );
529
+ }
530
+ }
531
+ }
532
+ ```
420
533
421
534
# [ .NET Framework 4.8] ( #tab/netframework48 )
422
535
423
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/Templates/HttpTrigger-CSharp-Isolated/HttpTriggerCSharp.cs":::
536
+ ``` csharp
537
+ using Microsoft .Azure .Functions .Worker ;
538
+ using Microsoft .Azure .Functions .Worker .Http ;
539
+ using Microsoft .Extensions .Logging ;
540
+ using System .Net ;
541
+
542
+ namespace Company .Function
543
+ {
544
+ public class HttpTriggerCSharp
545
+ {
546
+ private readonly ILogger <HttpTriggerCSharp > _logger ;
547
+
548
+ public HttpTriggerCSharp (ILogger <HttpTriggerCSharp > logger )
549
+ {
550
+ _logger = logger ;
551
+ }
552
+
553
+ [Function (" HttpTriggerCSharp" )]
554
+ public HttpResponseData Run ([HttpTrigger (AuthorizationLevel .Function , " get" )] HttpRequestData req )
555
+ {
556
+ _logger .LogInformation (" C# HTTP trigger function processed a request." );
557
+
558
+ var response = req .CreateResponse (HttpStatusCode .OK );
559
+ response .Headers .Add (" Content-Type" , " text/plain; charset=utf-8" );
560
+
561
+ response .WriteString ($" Welcome to Azure Functions, {req .Query [" name" ]}!" );
562
+
563
+ return response ;
564
+ }
565
+ }
566
+ }
567
+ ```
424
568
425
569
# [ .NET 8 Preview (isolated)] ( #tab/net8 )
426
570
427
- :::code language="csharp" source="~ /functions-quickstart-templates/Functions.Templates/Templates/HttpTrigger-CSharp-Isolated/HttpTriggerCSharp.cs":::
571
+ ``` csharp
572
+ using Microsoft .AspNetCore .Http ;
573
+ using Microsoft .AspNetCore .Mvc ;
574
+ using Microsoft .Azure .Functions .Worker ;
575
+ using Microsoft .Extensions .Logging ;
576
+
577
+ namespace Company .Function
578
+ {
579
+ public class HttpTriggerCSharp
580
+ {
581
+ private readonly ILogger <HttpTriggerCSharp > _logger ;
582
+
583
+ public HttpTriggerCSharp (ILogger <HttpTriggerCSharp > logger )
584
+ {
585
+ _logger = logger ;
586
+ }
587
+
588
+ [Function (" HttpTriggerCSharp" )]
589
+ public IActionResult Run (
590
+ [HttpTrigger (AuthorizationLevel .Function , " get" )] HttpRequest req )
591
+ {
592
+ _logger .LogInformation (" C# HTTP trigger function processed a request." );
593
+
594
+ return new OkObjectResult ($" Welcome to Azure Functions, {req .Query [" name" ]}!" );
595
+ }
596
+ }
597
+ }
598
+ ```
428
599
429
600
---
430
601
0 commit comments