Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UserSecretsId prevents any deployment of F# ASP.NET Core app to Azure App Service

I'm trying to deploy my F# ASP.NET Core app to Azure App Service. Unfortunately, each time I try to deploy, a <UserSecretsId> element is added to my project file, which as explained in this article causes the build to fail with the following error:

A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence

The article explains why the error occurs and instructs to fix it by removing the element from the project file and instead adding the user secrets ID in an AssemblyInfo.fs. I have tried this and can then build manually, but each time I try to deploy, the deployment process still adds a <UserSecretsId> element with a new ID in my project file, causing the build to fail.

Is there any way I can publish an F# ASP.NET Core app to Azure App Service?

(Also reported on Microsoft/visualfsharp#5549)

like image 795
cmeeren Avatar asked Aug 23 '18 06:08

cmeeren


People also ask

Where are secrets stored in production?

Secrets are stored in a separate configuration file in encrypted form. The secrets are then decrypted at runtime using AWS Key Management Service. This way you can version your secrets along with your application's source code, while avoiding storing secrets in clear text.

What are user secrets?

User Secrets ensures that there is no sensitive data included in the source code. Instead, the user secrets are stored outside of the project folder — inside the user's profile folder in the file system. However, one downside is that the data that is stored by User Secrets is not encrypted.

Where are user secrets stored Visual Studio?

By default, the inner text of UserSecretsId is a GUID. The inner text is arbitrary, but is unique to the project. In Visual Studio, right-click the project in Solution Explorer, and select Manage User Secrets from the context menu. This gesture adds a UserSecretsId element, populated with a GUID, to the project file.

Where is Secrets json stored?

Where are your secrets stored? Your secrets are stored in a JSON file under your user profile. In a Windows machine, they are stored in the %APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets. json file.


1 Answers

Add this to your .fsproj file to suppress the attribute generation.

<PropertyGroup>
 <GenerateUserSecretsAttribute>false</GenerateUserSecretsAttribute>
</PropertyGroup>

If you want to use user secrets, you will manually need to add the UserSecrets assembly attribute.

module Your.Namespace.AssemblyInfo
open Microsoft.Extensions.Configuration.UserSecrets
[<assembly: UserSecretsIdAttribute("Your UserSecretsId")>]
do()

Also, this workaround should be unnecessary in ASP.NET Core 2.2. See https://github.com/aspnet/Configuration/pull/872

like image 97
natemcmaster Avatar answered Nov 07 '22 14:11

natemcmaster