Skip to content

Commit 4992ef6

Browse files
removing range references for template code snippets
1 parent 3e903f1 commit 4992ef6

File tree

2 files changed

+242
-12
lines changed

2 files changed

+242
-12
lines changed

articles/azure-functions/migrate-version-1-version-4.md

Lines changed: 179 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,82 @@ In most cases, migrating requires you to add the following program.cs file to yo
213213

214214
# [.NET 6 (isolated)](#tab/net6-isolated)
215215

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+
```
217229

218230
# [.NET 6 (in-process)](#tab/net6-in-proc)
219231

220232
A program.cs file isn't required when running in-process.
221233

222234
# [.NET 7](#tab/net7)
223235

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+
```
225249

226250
# [.NET Framework 4.8](#tab/netframework48)
227251

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+
```
229276

230277
# [.NET 8 Preview (isolated)](#tab/net8)
231278

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+
```
233292

234293
---
235294

@@ -408,23 +467,135 @@ In version 4.x, the HTTP trigger template looks like the following example:
408467

409468
# [.NET 6 (isolated)](#tab/net6-isolated)
410469

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+
```
412498

413499
# [.NET 6 (in-process)](#tab/net6-in-proc)
414500

415501
:::code language="csharp" source="~/functions-quickstart-templates/Functions.Templates/Templates/HttpTrigger-CSharp/HttpTriggerCSharp.cs":::
416502

417503
# [.NET 7](#tab/net7)
418504

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+
```
420533

421534
# [.NET Framework 4.8](#tab/netframework48)
422535

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+
```
424568

425569
# [.NET 8 Preview (isolated)](#tab/net8)
426570

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+
```
428599

429600
---
430601

articles/azure-functions/migrate-version-3-version-4.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,82 @@ When migrating to run in an isolated worker process, you must add the following
152152

153153
# [.NET 6 (isolated)](#tab/net6-isolated)
154154

155-
:::code language="csharp" source="~/functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="23-29":::
155+
```csharp
156+
using Microsoft.Extensions.Hosting;
157+
158+
var host = new HostBuilder()
159+
.ConfigureFunctionsWebApplication()
160+
.ConfigureServices(services => {
161+
services.AddApplicationInsightsTelemetryWorkerService();
162+
services.ConfigureFunctionsApplicationInsights();
163+
})
164+
.Build();
165+
166+
host.Run();
167+
```
156168

157169
# [.NET 6 (in-process)](#tab/net6-in-proc)
158170

159171
A program.cs file isn't required when running in-process.
160172

161173
# [.NET 7](#tab/net7)
162174

163-
:::code language="csharp" source="~/functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="23-29":::
175+
```csharp
176+
using Microsoft.Extensions.Hosting;
177+
178+
var host = new HostBuilder()
179+
.ConfigureFunctionsWebApplication()
180+
.ConfigureServices(services => {
181+
services.AddApplicationInsightsTelemetryWorkerService();
182+
services.ConfigureFunctionsApplicationInsights();
183+
})
184+
.Build();
185+
186+
host.Run();
187+
```
164188

165189
# [.NET Framework 4.8](#tab/netframework48)
166190

167-
:::code language="csharp" source="~/functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="2-20":::
191+
```csharp
192+
using Microsoft.Extensions.Hosting;
193+
using Microsoft.Azure.Functions.Worker;
194+
195+
namespace Company.FunctionApp
196+
{
197+
internal class Program
198+
{
199+
static void Main(string[] args)
200+
{
201+
FunctionsDebugger.Enable();
202+
203+
var host = new HostBuilder()
204+
.ConfigureFunctionsWorkerDefaults()
205+
.ConfigureServices(services => {
206+
services.AddApplicationInsightsTelemetryWorkerService();
207+
services.ConfigureFunctionsApplicationInsights();
208+
})
209+
.Build();
210+
host.Run();
211+
}
212+
}
213+
}
214+
```
168215

169216
# [.NET 8 Preview (isolated)](#tab/net8)
170217

171-
:::code language="csharp" source="~/functions-quickstart-templates/Functions.Templates/ProjectTemplate_v4.x/CSharp-Isolated/Program.cs" range="23-29":::
218+
```csharp
219+
using Microsoft.Extensions.Hosting;
220+
221+
var host = new HostBuilder()
222+
.ConfigureFunctionsWebApplication()
223+
.ConfigureServices(services => {
224+
services.AddApplicationInsightsTelemetryWorkerService();
225+
services.ConfigureFunctionsApplicationInsights();
226+
})
227+
.Build();
228+
229+
host.Run();
230+
```
172231

173232
---
174233

0 commit comments

Comments
 (0)