Mark Szabo
Mark Szabo

Reputation: 10498

Azure Functions #r is only allowed in scripts

I'm trying to get a ConnectionString in an Azure Functions App. I've created a new Functions App in Visual Studio, and was using this sample, which says I need to add this line to the Function.cs:

#r "System.Configuration"

But when I try it, IntelliSense says that

#r is only allowed in scripts

Build fails too.

IntelliSense error

Already tried renaming the file to .csx, without success. According to the developer reference, it should work: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp

Upvotes: 1

Views: 4861

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

Visual Studio is creating a project which gets precompiled before being run as a Function App. Effectively, it's just a C# class library which references Functions SDK NuGet package.

To reference another library or NuGet packages, just use the usual ways to do so for class libraries: Add Reference or Add NuGet Package.

Thus, no #r directive is needed.

Upvotes: 4

Related Questions