Skip to content

Extensions.json not generating due to missing trailing slash in NugetPackageRoot #4383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brettsam opened this issue May 3, 2019 · 20 comments · Fixed by Azure/azure-functions-vs-build-sdk#310
Assignees

Comments

@brettsam
Copy link
Member

brettsam commented May 3, 2019

Forking an issue reported here to a new issue.

Copying relevant comments from @pgussow here:

For me this is the error it is giving:
Error processing D:\projects\FunctionApp\bin\Debug\netstandard2.0\bin\Microsoft.CSharp.dll for extension metadata: FileLoadException Could not load file or assembly 'Microsoft.CSharp, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

My scenario is a bit different though: I had a (working) solution. Then I had to migrate to a different repo, so I copied the projects into a new solution. And all of a sudden the extensions.json does not get generated anymore. On file level (within the solution) the files are equal. So I have no idea where this is coming from. The only difference I see is that they both use a different global Nuget cache folder...


Unfortunately no. It was not generating any extensions.json file anymore. So based on other Google-results I added the package Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator explicitly to my FunctionApp project.

I'm expecting 2 extensions there:

Service Bus Trigger
AutofacOnFunctions (lib I'm using for DI).
Maybe this gives a bit of a clue. Based on the ouytput might it be the sequencing of the targets? As the metadata is called before the function.json is generated?


I also tried with using the 1.1.0 version of the ExtensionsMetadataGenerator. No luck unfortunately

build_output_1.1.0.txt

As you can see in the output the Microsoft.CSharp-error is gone. What I did was create a new project from scratch using the VS2017 wizard. Then I copied in the old function codes and fixed the dependencies via Nuget installs.

Unfortunately the extensions.json is still empty :(


Based on your reply I think I figured it out what is going wrong: When I ran the command which my logging states:
Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "D:\projects\SomeComp.IntegratieEnOntwikkeling\Azure\FunctionApps\Integrationhub\SomeComp.IntegrationHub2\bin\Debug\netcoreapp2.1" "D:\projects\SomeComp.IntegratieEnOntwikkeling\Azure\FunctionApps\Integrationhub\SomeComp.IntegrationHub2\bin\Debug\netcoreapp2.1\extensions.json"

again an empty extensions.json. But now I added the \bin to my source and then it does get generated.

Then looking at the Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets file I guess the problem is that the _IsFunctionsSdkBuild is not true and thus the _FunctionsTaskFramework is not filled properly. But this is filled from the functions SDK.

So I guess I need to figure out the way to force VS2017 Build to use the Core version instead of the Full version


To summarize my findings:

When using Microsoft.NET.Sdk.Functions 1.0.27 I get the Microsoft.CSharp 4.0.4.0 exception.
When using Microsoft.NET.Sdk.Functions 1.0.24 I DO NOT get the Microsoft.CSharp 4.0.4.0 exception.
After adding these lines to my project file the extension generation works:
<_FunctionsTaskFramework>netcoreapp2.1
So my conclusion is that for some reason the _FunctionsTaskFramework does not get filled. And that is causing the ExtensionMetadataGenerator to look into the wrong folder for the assemblies to parse.
Because if I manually run the tool and add the \bin to the command then the extensions.json gets generated properly.

Would it be usefull to attach the complete build output for analysis?

@brettsam
Copy link
Member Author

brettsam commented May 3, 2019

@pgussow -- one thing that we've found is that directly referencing ExtensionsMetadataGenerator does not work correctly. You should remove that and stick with the newest Microsoft.NET.SDK.Functions version (currently 1.0.27) -- which includes the latest ExtensionsMetadataGenerator.

@brettsam
Copy link
Member Author

brettsam commented May 3, 2019

I grabbed all of your packages, replaced Microsoft.NET.Sdk.Functions with 1.0.27 and I do see the extensions.json appearing... can you try a simple project like this?

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.27" />
    <PackageReference Include="Autofac" Version="4.2.1" />
    <PackageReference Include="AutofacOnFunctions" Version="1.0.14" />
    <PackageReference Include="AutoMapper" Version="8.1.0" />
    <PackageReference Include="Dapper" Version="1.60.6" />
    <PackageReference Include="Dapper.FluentMap" Version="1.8.0" />
    <PackageReference Include="Dapper.Oracle" Version="1.2.0" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.0.0.1-preview" />
    <PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.1" />
    <PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.3" />
    <PackageReference Include="Microsoft.Azure.Management.ApiManagement" Version="4.0.6-preview" />
    <PackageReference Include="Microsoft.Azure.ServiceBus" Version="3.4.0" />
    <PackageReference Include="Microsoft.Azure.Storage.Common" Version="10.0.2" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.0.4" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
    <PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.18.6" />
    <PackageReference Include="System.Private.ServiceModel" Version="4.5.3" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

@pgussow
Copy link

pgussow commented May 6, 2019

Does the extensions.json also appear in the correct folder? And does it have the correct content? I've seen that it generates an empty extensions.json as it was not taking the bin folder to examine the DLLs. Also I guess you need to have a function which uses the MessageBus trigger?

I've tried a simple project as you've mentioned, but no extensions.json al alll in the build folder. I've attached the simple project I used.
FunctionApp.zip

@foconnor-DS
Copy link

I too am having this issue. I've spent about 3 hours reading all the past issues w.r.t extensions.json being empty or not generated.

I've tried combinations of _IsFunctionsSdkBuild true/false with and without Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator (1.1.0). i either generate an empty extensions.json or no extension.json at all.

I uninstalled all .Net Core SDK's and Runtimes, and reinstalled VS 2019 Preview.

I cleared all my nuget caches.

Simple HTTP triggers work ( no extensions ). As soon as I add "Microsoft.Azure.WebJobs.Extensions.Storage" and try to use a QueueTrigger:

[5/6/2019 7:09:04 PM] The following 1 functions are in error:
[5/6/2019 7:09:04 PM] QueueTrigger: The binding type(s) 'queueTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.

My project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.6" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.27" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

I made my own extensions.json:

{
  "extensions": [
    {
      "name": "AzureStorage",
      "typeName": "Microsoft.Azure.WebJobs.Extensions.Storage.AzureStorageWebJobsStartup, Microsoft.Azure.WebJobs.Extensions.Storage, Version=3.0.6, Culture=neutral, PublicKeyToken=null"
    }
  ]
}

If i stick this in ./bin/Debug/netcoreapp2.2/ (where the host.json is), it still won't work.

If however if i move it into ./bin/Debug/netcoreapp2.2/bin/

move $(OutDir)extensions.json $(OutDir)\bin

then it will work.

@brettsam
Copy link
Member Author

brettsam commented May 6, 2019

I'm trying to get this to repro and every time I do it, I'm getting extensions.json generated. Let's see what else could be different:

  • What command are you both running to build?
  • What is your output when you run dotnet --info from the same folder as your build?

Another option is to run your build with the /bl flag -- it will produce a binlog file which you can look at with the structured log viewer at http://www.msbuildlog.com/. That may highlight why we're skipping the extension.json creation (or not copying it). If you'd like to send that file to me to look at, that would work as well -- my email is in my profile. But note that the log does include a dump of env vars, so don't share it publicly.

@foconnor-DS
Copy link

foconnor-DS commented May 6, 2019

Mine is a bare-bones VS 2019 preview 3.0 project and build ( F5 ).

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.203
 Commit:    e5bab63eca

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.203\

Host (useful for support):
  Version: 2.2.4
  Commit:  f95848e524

.NET Core SDKs installed:
  2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
  2.2.203 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

@brettsam
Copy link
Member Author

brettsam commented May 6, 2019

@foconnor-DS -- what about when you go to the directory and do a dotnet build? Does that generate extensions.json? I'm trying your project as well -- doing command-line builds and in VS 2019 (v16.0.3) -- and it's generating for me. I'm trying to think if there's anything else environmental that could be affecting the build.

@foconnor-DS
Copy link

Cleared bin/obj, ran a nuget command line, and then msbuild with binlog. No change, sending you that binlog now.

@brettsam
Copy link
Member Author

brettsam commented May 6, 2019

We figured out @foconnor-DS's issue -- it had to do with the NugetPackageRoot environment variable missing a trailing slash. Our targets file (incorrectly) assumes there'll be one so it was looking in the wrong place. I'll fix that soon.

@pgussow -- can you check that in your setup? The binlog made it pretty clear when I looked at it. I saw a log like this:

NoImport: $(NuGetPackageRoot)microsoft.azure.webjobs.script.extensionsmetadatagenerator\$(ExtensionsMetadataGeneratorVersion)\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets at (60;3) Not imported due to false condition; (Exists('$(NuGetPackageRoot)microsoft.azure.webjobs.script.extensionsmetadatagenerator\$(ExtensionsMetadataGeneratorVersion)\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets')) was evaluated as (Exists('C:\data\.nugetmicrosoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.0\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets')).

@pgussow
Copy link

pgussow commented May 7, 2019

I guess I'm seeing the same thing:
image
and thus:
image

@pgussow
Copy link

pgussow commented May 7, 2019

image
I've added the trailing \ to my custom Nuget.Config. Now the import message is gone, but the result is still the same. It looks to the wrong folder to generate the bindings. It should look in the \bin folder to find the assemblies to examine.

@brettsam
Copy link
Member Author

brettsam commented May 7, 2019

Okay -- we're getting somewhere. Can you share your exact project file and command you're running to build?

@pgussow
Copy link

pgussow commented May 8, 2019

I've sent you the binlog and the exact project file. The command I run is either
dotnet build /bl
or just a build from VS2017. It doesn't make a difference in outcome.

@brettsam brettsam changed the title Extensions.json not generating Extensions.json not generating due to missing trailing slash in NugetPackageRoot May 8, 2019
@brettsam
Copy link
Member Author

brettsam commented May 8, 2019

I believe this isn't working because of the direct reference to ExtensionsMetadataGenerator. I'm working on a fix for that, but if you remove that nuget package, I believe it will all work for you.

@pgussow
Copy link

pgussow commented May 9, 2019

I removed the direct reference. Then the extensions.json gets generated in the proper folder (because of the trailing \ in the NuGetPackageRoot. But if I remove the
<_FunctionsTaskFramework>netcoreapp2.1</_FunctionsTaskFramework>
in the csproj then the json remains empty. Adding that line generates the correct extensions.json in the correct location

@brettsam
Copy link
Member Author

https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions/1.0.28 has been released, which should fix the "missing trailing backslash" issue on the NUGET_PACKAGES and NugetPackageRoot properties.

@pgussow -- if you're still seeing issues with this package, can you send me another binlog of a failed build? You shouldn't need the _FunctionsTaskFramework property to be explicitly set.

@pgussow
Copy link

pgussow commented May 15, 2019

So far so good. I don't see any issues anymore.

@enternet
Copy link

1.0.28 changed nothing for me. But after I uninstalled all sdks except one 2.2.204, the error gone.

@brettsam
Copy link
Member Author

@enternet that's interesting. If you are able to reproduce this again, could you try running with a /bl switch to the end of it, and emailing me the msbuild.binlog file that it generates? My email is in my github profile.

@enternet
Copy link

OK, lets wait the next sdk. I'm not sure that my case is common case. I had more then 50 sdks.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants