0

How to convert old project.json to function.proj xml for Azure Function App

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Newtonsoft.Json": "10.0.3",
        "System.ServiceModel.Primitives":"4.4.0",
        "MongoDB.Bson": "2.4.0",
        "MongoDB.Driver": "2.4.0",
        "MongoDB.Driver.Core": "2.4.0"
      }
    }
   }
}
user3744961
  • 53
  • 1
  • 7

1 Answers1

1

You just need to create the xml as below:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
        <PackageReference Include="MongoDB.Bson" Version="2.4.0" />
        <PackageReference Include="MongoDB.Driver" Version="2.4.0" />
        .......
    </ItemGroup>
</Project>

Copy all of the package information(the path and the version) from the old file to this xml. You can refer to this tutorial.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • Thanks for the info. i am getting error error CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?) for using System.ServiceModel.Description; Also error CS0246: The type or namespace name 'MongoDB' could not be found (are you missing a using directive or an assembly reference?) – user3744961 Mar 17 '20 at 08:31
  • @user3744961 May I know the version of your azure function ? When you convert the project.json to function.proj, you create a new function app or just use the old function app ? – Hury Shen Mar 17 '20 at 08:37
  • created new function app. version - 3; Runtime version: 3.0.13139.0 – user3744961 Mar 17 '20 at 08:45
  • @user3744961 I met the same problem before and I searched for some information just now. According to this [post](https://stackoverflow.com/questions/58728279/service-model-assembly-error-with-azure-functions-v2-net-core-2-1), it seems we can just use "System.ServiceModel.Primitives" in azure function v1. – Hury Shen Mar 17 '20 at 09:13
  • @user3744961 You can try to copy the package's dll to azure function bin folder and use #r to import it in your function (But I've tried this way before and failed). – Hury Shen Mar 17 '20 at 09:46