Skip to content

Using existing Azure Functions project #195

@dochoss

Description

@dochoss

Hey team, I'd like to be able to use an existing Azure Functions project with my Aspire deployment to take advantage of Flex Consumption, but I'm getting compile errors when trying to use the **AsExisting() methods. I'm using VS Code with the latest package versions. I've searched the docs for examples of using AsExisting with Functions projects but can't seem to find clear guidance on how to do this (if it's possible).

AppHost.cs

var existingFuncName = builder.AddParameter("existingFuncName", value: "my-funcs");
var existingFuncResourceGroup = builder.AddParameter("existingFuncResourceGroup", value: "my-rg");

var funcs = builder.AddAzureFunctionsProject<Projects.MyProject_Functions>("functions")
    .RunAsExisting(existingFuncName, existingFuncResourceGroup);  // ERROR ON THIS LINE, red squiggles under "RunAsExisting"

Error text

The type 'Aspire.Hosting.Azure.AzureFunctionsProjectResource' cannot be used as type parameter 'T' in the generic type or method 'ExistingAzureResourceExtensions.RunAsExisting<T>(IResourceBuilder<T>, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>?)'. There is no implicit reference conversion from 'Aspire.Hosting.Azure.AzureFunctionsProjectResource' to 'Aspire.Hosting.ApplicationModel.IAzureResource'.[CS0311](https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS0311))

AppHost.csproj

<Project Sdk="Aspire.AppHost.Sdk/13.1.0">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <UserSecretsId><REDACTED></UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyProject.ApiService\MyProject.ApiService.csproj" />
    <ProjectReference Include="..\MyProject.Functions\MyProject.Functions.csproj" />
  </ItemGroup>

  <ItemGroup>
      <PackageReference Include="Aspire.Hosting.Azure.Sql" Version="13.1.0" />
      <PackageReference Include="Aspire.Hosting.Azure.Functions" Version="13.1.0" />
      <PackageReference Include="Aspire.Hosting.Azure.Storage" Version="13.1.0" />
      <PackageReference Include="Aspire.Hosting.JavaScript" Version="13.1.0" />
      <PackageReference Include="Aspire.Hosting.OpenAI" Version="13.1.0" />
      <PackageReference Include="Scalar.Aspire" Version="0.7.3" />
    </ItemGroup>

</Project>

User Secrets snippet

{
  "Azure:SubscriptionId": "<my subscription id>",
  "Azure:ResourceGroup": "my-rg",
  "Azure:Location": "eastus2"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions