Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

June 19, 2025

Upgrading to .NET 8 Isolated Azure Functions: A Complete Step-by-Step Guide

Introduction

The .NET Isolated Worker Model enables developers to build Azure Functions using a .NET console app project that targets a supported .NET runtime. This model provides greater flexibility, improved performance, and better debugging capabilities compared to the in-process model.

In this guide, we will walk you through upgrading your existing Azure Functions project to .NET 8 using the isolated worker model.


Required Files in a .NET Isolated Project

A .NET-isolated Azure Functions project requires the following essential files:

  • host.json — Configuration file for host settings.
  • local.settings.json — Stores local configurations.
  • .csproj file — Defines the project and dependencies.
  • Program.cs — The entry point for the application.
  • Function code files — Contain your function implementations.

Updating the .csproj File

The first step is to convert the project file and update its dependencies.


Existing .NET 3.x Project (.csproj)


<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="Functions\host.json" />
    <None Remove="stylecop.json" />
  </ItemGroup>
  <ItemGroup>
    <AdditionalFiles Include="stylecop.json" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Core" Version="1.13.0" />
    <PackageReference Include="Azure.Storage.Common" Version="12.7.2" />
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.4" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.25" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.27" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.9" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.4.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.12" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.4" />
    <!-- Your remaining packages -->
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Updated .NET 8 Project (.csproj)

Make the following changes:

  • Set <TargetFramework> to net8.0.
  • Set <AzureFunctionsVersion> to v4.
  • Add <OutputType>Exe</OutputType>.
  • Replace Microsoft.NET.SDK.Functions With the following packages:


<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>disable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    <!-- Your remaining packages -->
  </ItemGroup>
</Project>

Add the following new ItemGroup:


<ItemGroup> 
  <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" /> 
</ItemGroup>

After you make these changes, your updated project should look like this:


<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>disable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.11.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.6.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

To make all the above changes automatically, we can make use of the .NET UPGRADE ASSISTANT Extension.


Your isolated worker model application should not reference any packages from Microsoft.Azure.WebJobs.* namespace or Microsoft.Azure.Functions.Extensions.

If you have any remaining references to these, they should be removed.


Updating the host.json File

Your host.json The file plays a critical role in configuring the runtime behavior of your Azure Functions. Below is a sample configuration for an upgraded .NET 8 isolated function:


{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    },
    "functionTimeout": "00:05:00", // Set the time according to your needs
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[4.0.0, 5.0.0)"
    }
}

Note: Please add this functionTimeout based on your function app plan. More details can be found here.

Updating the Program.cs File

The Program.cs file replaces FunctionStartup and serves as the application’s entry point


using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var builder = new HostBuilder();
if (builder != null)
{
    builder.ConfigureFunctionsWebApplication().ConfigureServices(service =>
    {
        service.AddHttpClient();
        service.AddLogging();
        // Add configurations according to your needs
    });
}
// Build and run the application
builder.Build().Run();

The program.cs file will replace any file that has the FunctionStartup attribute, which is typically a startup.cs file.

In places where your FunctionStartup code would reference IFunctionHostBuilder.Services, you can instead add statements within the.ConfigureService() method of the HostBuilder in your Program.cs.

Once you have moved everything from any existing FunctionStartup to the program.cs file, you can delete the FunctionStartup attribute and the class it was applied to.


Function Signature changes

Before (In-Process Model)


public static class Function1
{
    [FunctionName("Function1")]
    public static IActionResult Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        return new OkObjectResult("Hello, Azure Functions!");
    }
}

After (Isolated Worker Model)


public class Function1
{
    private readonly ILogger<Function1> _logger;

    public Function1(ILogger<Function1> logger)
    {
        _logger = logger;
    }

    [Function("Function1")]
    public async Task<HttpResponseData> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
    {
        this._logger.LogInformation("C# HTTP trigger function processed a request.");
        var response = req.CreateResponse(HttpStatusCode.OK);
        await response.WriteStringAsync("Hello, Azure Functions!");
        return response;
    }
}

Updatinglocal.settings.json

Modify FUNCTIONS_WORKER_RUNTIME to dotnet-isolated.


{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

Publishing .NET 8 (Isolated) Azure Functions via Visual Studio

Follow these steps to deploy your function app to Azure using Visual Studio:

Download the Publish Profile

  • Open the Azure Portal.
  • Navigate to your Function App.
  • Go to Deployment Centre> Publish Profile and download the file.

Prepare Your Solution

  • Open your project in Visual Studio.
  • Set the build configuration to Release Mode.
  • Clean the solution to remove old build files.
  • Build the solution to ensure there are no errors.

Publish the Function App

  • In Solution Explorer, right-click on the function app project and select Publish.
  • Choose Import Profile as the publish target.
  • Browse and select the downloaded publish profile.
  • Click Publish and wait for the deployment to complete.

Once the process finishes, your function app is successfully deployed to Azure.


Upgrading in the Azure Portal

Upgrading your function app to the isolated model consists of the following steps:

Navigate to Settings > Environment Variables.

  • Update FUNCTIONS_EXTENSION_VERSION from ~3 to ~4.
  • Change FUNCTIONS_WORKER_RUNTIME to dotnet-isolated.

Under Settings > Configuration, ensure:

  • Runtime version is ~4.
  • General Settings .NET Version is .NET 8 Isolated.


Troubleshooting Error: “Building Configuration in an External Startup Class”Solution:

  • Go to Storage Account > Data Storage > Tables > AzureFunctionsDiagnosticEventsDate.
  • Delete or clear the table.


Conclusion

Upgrading to the .NET 8 Isolated Worker Model enhances the performance and maintainability of your Azure Functions. By following these steps, you ensure a smooth transition while leveraging the latest advancements in .NET and Azure Functions.

February 4, 2021

[Issue Resolved] : Error occurred in deployment step 'Recycle IIS Application Pool': Invalid namespace SharePoint

Problem/Issue:
Recently, while developing a custom visual web part for SharePoint 2019 On-Premise version, I was facing below error on deployment of the solution:

"Error occurred in deployment step 'Recycle IIS Application Pool': Invalid namespace"

Analysis & findings:
In Past, we'd already faced such issue and it was related to .NET Framework. So, I tried with reducing current version to 4.5 framework but it didn't help much.
Then, I did bit googling, and spent more time to analyze the the issue further. And finally, I was able to find the root cause of the issue. It was related to changes in configuration of development environment.

Solution:
We need to add "IIS 6 WMI Compatibility" feature in our development machine to fix the issue. To add it, we need to follow below steps:
  • If you are using windows server, go to server manager. 
  • Click on “Add Roles and Feature”.
  • It will open “add feature” dialog. Click next till you reach “Server Roles”.

  • Expand “Web Server (IIS)”
  • Expand “Management Tools”
  • Expand “IIS 6 Management Compatibility”
  • Now, check “IIS 6 WMI Compatibility”, “IIS 6 Metabase Compatibility” & “IIS 6 Management Console” and click Next.
Note - In my case, the first two features were already installed. If it is not installed in your machine, please select it as well.
  • Click Next and move to feature tab.
  • Click Install in confirmation installation screen.
  • It will start installing the feature. Wait for the completion.
  • Click close.
  • Restart the visual studio and try to deploy the project and it will deploy successfully. 

If you have any questions you can reach out our SharePoint Consulting team here.

June 13, 2013

Dlls not deployed to GAC - SharePoint 2013, Visual Studio 2012, .Net FW 4.5

​When you create a SharePoint 2013 project in Visual Studio 2012 and I want to deploy it, it deploys fine, but DLL is not in the Global Assembly Cache.
We check for assembly in c:\windows\assembly but it does not appear there. Don't panic!!!
Assembly folder for .NET 4.0 and up have changed to c:\windows\microsoft.net\assembly
If you have any questions you can reach out our SharePoint Consulting team here.

VS2012 C# compiler issue solution

If you encounter problem while creating new project in VS2012 or 2013 VM, follow steps given below:
Error: C#2012 compiler could not be created
Solution 1:
Check the following settings: Tools->Options->Text Editor->C#->General->Auto list members
Tools->Options->Text Editor->C#->General->Parameter information
Also check
Tools->Options->Text Editor->C#->Intelligence->
Show completion list after a character is typed
Also,
Tools –> Import and Export Settings -> Reset all Settings
Also,
Instead of changing it for only C#, change it for all the languages
Tools > Options > Text Editor > All Languages
Solution 2:
Run following command on VS2012 x86 Native Tools Command Prompt
gacutil /u Microsoft.VisualStudio.CSharp.Services.Language.Interop
If you are unable to delete the assembly, follow steps given in
http://support.microsoft.com/kb/873195
Solution 3:
Install patch available on path
\\192.168.2.254\Softwares\Microsoft Sharepoint 2013\Other softwares\VS10-KB980610-x86.exe


If you have any questions you can reach out our SharePoint Consulting team here.

October 22, 2012

Nuget for Visual Studio

Nuget​ is a package manager for visual studio. It allows developers to setup third party libraries in the project easily. For example if you are working on a console application to migrate documents and want to use log4net library. You can just search for log4net in package manager gallery and add reference to it. All web.config/app.config and references will be auomatically updated by nuget.
Install nuget to your visual studio and start learning new libraries now!


If you have any questions you can reach out our SharePoint Consulting team here.

log4net - logging makes easy

Use case:
You are working on some task which requires logging to event viewer, file, console or combination of such mediums.
Why?
Most of the time you have to write same string to console and file with two different lines of code. That will cause the code look ugly and while changing messages, developer has to make sure to update both lines. Additional errors may occure due to the mistakes.
Prerequisites:
Install nuget for visual studio.
How?
Right click on your project and click on library package manager. Search for log4net and choose appropriate version as per your visual studio application. Click on install.
What are different mediums where I can log? 
  • MS SQL Server
  • MS Access
  • Oracle 9i
  • Oracle 8i
  • IBM DB2
  • SQLite
  • Asp.Net Trace
  • Console
  • EventLog
  • File
  • SMTP
  • much more
Example:
See vss_br/bms/trunk/bms/bmsmigration project in vss for rerence implementation in console application for logging in console and file.
References:
  1. Code project tutorial
  2. Configuration Examples
  3. Log4net config example to Log into console and file both
  4. Official Home page


If you have any questions you can reach out our SharePoint Consulting team here.

June 11, 2012

Creating a Custom Action by Using a Feature

The following steps create a custom action in Visual Studio 2010.
The procedures in this section assume a development environment where SharePoint 2010 is installed and configured, Microsoft Visual Studio 2010 is installed and the currently logged-in user has administrative rights on the SharePoint environment for deployment purposes.
To Create a Custom Action by Using a Feature
  • In Visual Studio 2010, click New Project, expand the SharePoint node, click 2010, and then click Empty SharePoint Project. Name the project E-mail a Link and then click OK.
  • In the SharePoint Customization Wizard, select the local SharePoint site that can be used for debugging and whether the solution will be deployed as a sandboxed or farm solution as shown in Figure 1.
  • Click Finish.
    Figure 1. Specify the deployment method 

  • In Solution Explorer, right-click the Features node and then click Add Feature as shown in
    Figure 2.
    Figure 2. Add new feature
  • Name the feature E-mail a Link and add a description as shown in Figure 3.
    Figure 3. Name the feature
  • In Solution Explorer, right-click the E-Mail a Link project, select Add, and then select New Item as shown in Figure 4.
    Figure 4. Add a new item to the project
  • In the Add New Item dialog box, select the Empty Element template, type E-Mail a Link as the name, and then click Add as shown in
    Figure 5.
    Figure 5. Add an element to the project
  • Open the Elements.xml file inside E-Mail a Link and then replace the file content with the following code example. If you like to apply this E-mail a Link to all the Lists, Change RegistrationsType From "ContentType" to "List" and RegistrationId from unique number to "101"
    XML
    1. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction
      Description="Email A Link"
      Title="Email A Link"
      Id="{E538E8C7-65DA-454E-AD87-4A603B6CC569}"
      Location="CommandUI.Ribbon"
      RegistrationId="0x0100...(put actual Id here)"
      RegistrationType="ContentType"
      Sequence="1"
      Rights="ViewListItems"
    xmlns="http://schemas.microsoft.com/sharepoint/">
    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Define the (UI) button to be used for this custom action -->
    <CommandUIDefinitions>

    <CommandUIDefinition Location="Ribbon.ListForm.Display.Actions.Controls._children">
    <Button Id="{B511A716-54FF-4EAE-9CBE-EA02B51B626E}"
    Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
    Image16by16="/_layouts/1033/images/formatmap16x16.png"
    Image16by16Top="-16" Image16by16Left="-88"
    Sequence="500"
    LabelText="E-mail a Link"
    Description="E-mail a Link"
    TemplateAlias="o2"
    />
    </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <!-- Define the action expected on the button click -->
    <CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:mailThisPage();" />
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>
    <CustomAction Location="ScriptLink" ScriptSrc="/_layouts/xxxx/xxxx.js"/>
    </Elements>
  • Save the file.
  • Add the E-Mail a Link element to the E-mail a Link feature as shown in Figure 6.
    Add the E-Mail a Link element to the E-mail a Link
    feature as shown in Figure 6.
  • Right click the solution name and then click Deploy as shown in Figure 7. Visual Studio 2010 will build and deploy the solution to the farm.
    Figure 7. Build and deploy the solution
  • Navigate to the local site, Enable the feature E-mail a Link.
  • Add custom and name it as Promotion list, and then Click on View Item. Observe the "E-mail a Link" under the Action Group as shown in Figure 8.
    Figure 8. The E-mail a Link button
  • Click the "E-mail a Link" button and notice the default Email application open with the link to this item.
If you have any questions you can reach out our SharePoint Consulting team here.

October 15, 2009

How-To: Add intellisense support for Jquery inside UserControl page in Visual Studio 2008 IDE

If you have just downloaded and referenced Jquery , you might be wondering how to add intellisense support for the same in user control.


A blog post by scott gu shows very nicely how microsoft has included a hotfix for visual studio 2008 sp1 which enables jquery intellisense support (provided you also reference the jquery vsdoc file in your project).



I was trying out JQuery on normal aspx page and it worked just fine. However I soon ran into problem while using it in a user control, the intellisense simply was not working. I did a quick work around for the same which is as follows:

Just write down if statements within your user control which evaluates to false always and reference the jquery script file there. Note I already have a referenced jquery lib in my master page, and I don’t want it to be rendered a second time here, hence the if statement.

This code will server two purposes: firstly it will allow visual studio IDE to detect and display intellisense when you use jquery syntax in your user control, secondly it won’t show up in the rendered html since if always evaluates for false.


 
 
 
There may be other optimal solutions available out there, but this code did the trick for me and it can be removed before publishing the site for production purposes.

If you have any questions you can reach out our SharePoint Consulting team here.

Posted By: Bhavyesh