Robin
Robin

Reputation: 451

Azure Function reference in classlibrary

I'm using VS2017 (C#) with Azure Function. It works fine. So now I'm trying to setup a class library for common functions. I couldn't find the reference to Microsoft.NET.Sdk.Functions (1.0.0) When I try to Add Reference (It was installed in vs2017, not Nuget) so I copied it directly from working azure csproj to my one classlibrary csproj

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0" />

Then now when I build the class library, I get a "error MSB4057: The target "RunResolvePublishAssemblies" does not exist in the project."

How do I solve that?

Upvotes: 0

Views: 779

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28067

As far as I know, if we want to use azure function in class library, we need set the project SDK to "Microsoft.NET.Sdk". The RunResolvePublishAssemblies is included in the Microsoft.NET.Sdk.

Like this:

<Project  Sdk="Microsoft.NET.Sdk">

And delete the class library's default compile file.

<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

Because the 'Microsoft.NET.Sdk' includes 'Compile' items from your project directory by default.

Then it will work well.

The csporj is like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Sdk="Microsoft.NET.Sdk" >
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System"/>

    <Reference Include="System.Core"/>
    <Reference Include="System.Xml.Linq"/>
    <Reference Include="System.Data.DataSetExtensions"/>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha3" />

    <Reference Include="Microsoft.CSharp"/>

    <Reference Include="System.Data"/>

    <Reference Include="System.Net.Http"/>

    <Reference Include="System.Xml"/>
  </ItemGroup>
  <ItemGroup>

  </ItemGroup>

 </Project>

This is as same as the azure function csproj. So I don't suggest you add Azure Function reference in classlibrary. You could directly create one azure function project.

Upvotes: 2

Related Questions