project.json is not restoring packages if you make an Azure function in version 2.x
It should be as follows:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</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"/>
<PackageReference Include="MongoDB.Driver.Core" Version="2.4.0"/>
</ItemGroup>
</Project>
kindly make these changes to avoid wastage of time
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi @Hariharnath-Paduchuru Thank you for reporting this issue! We will investigate and make any necessary changes.
@Hariharnath-Paduchuru The way of dealing with packages has indeed changed in v2 from listing them in project.json to having them as project level dependencies in extensions.csproj.
We have assigned this issue to the content author to update as appropriate.
@Hariharnath-Paduchuru we are very sorry for your inconvenience. We are currently in the process of updating this article to support the new way you must add NuGet package references to a C# script project in .NET Core 2.x.
@mike-urnun-msft please assign to @craigshoemaker so that he can resolve this issue when the update is published.
Hi Docs team,
Please notice that currently uploading extensions.csproj file is INCORRECT for using Nuget packages in the doc at https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#using-nuget-packages
To my knowledge, extensions.csproj is for getting the essentials for some triggers after v2 breaking changes. For example, if I add an EventGrid trigger, I need to install EventGrid extensions/SDKs first (via portal or using extensions.csproj). Moreover, I tested this way to install Nuget packages instead of extensions. It's not working - popped up "assembly missing" errors while calling the namespace by "using xxxxxx" in-code.
Back to the topic, updating the doc, you may follow and test below - how to install Nuget packages for v1 and v2:
For v1,
project.json
https://stackoverflow.com/questions/36411536/how-can-i-use-nuget-packages-in-my-azure-functions
when succeeded, you'd find project.lock.json generated.
For v2,
function.proj
when succeeded, you'd find project.assets.json generated.
Hope it helps!
@ggailey777 and @craigshoemaker - any update on these docs? If not, I can make a draft / poke some people on our team to submit a PR
@mhoeger I got verification from PM that @yeahsicy's suggestion is correct. I just pushed a PR to get this updated.
Most helpful comment
Hi Docs team,
Please notice that currently uploading extensions.csproj file is INCORRECT for using Nuget packages in the doc at https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#using-nuget-packages
To my knowledge, extensions.csproj is for getting the essentials for some triggers after v2 breaking changes. For example, if I add an EventGrid trigger, I need to install EventGrid extensions/SDKs first (via portal or using extensions.csproj). Moreover, I tested this way to install Nuget packages instead of extensions. It's not working - popped up "assembly missing" errors while calling the namespace by "using xxxxxx" in-code.
Back to the topic, updating the doc, you may follow and test below - how to install Nuget packages for v1 and v2:
For v1,
project.json
https://stackoverflow.com/questions/36411536/how-can-i-use-nuget-packages-in-my-azure-functions
when succeeded, you'd find project.lock.json generated.
For v2,
function.proj
https://blogs.msdn.microsoft.com/cjaliaga/2018/01/21/installing-nuget-packages-in-azure-functions-2-x-runtime-preview/
when succeeded, you'd find project.assets.json generated.
Hope it helps!