We are getting this error when attempting to upgrade the Azure functions project. This is the log file we are getting
Restoring packages for
C:\Users\User\Source\Repos\xxx_FileService\xxx.AzureFunctions\xxx.AzureFunctions\SE.AzureFunctions.csproj...
Detected package version outside of dependency constraint: Microsoft.NET.Sdk.Functions 1.0.7 requires Newtonsoft.Json (= 9.0.1) but version Newtonsoft.Json 10.0.3 was resolved.
Detected package downgrade: Microsoft.Azure.WebJobs from 2.1.0-beta4 to 2.1.0-beta1. Reference the package directly from the project to select a different version.
xxx.AzureFunctions -> Microsoft.NET.Sdk.Functions 1.0.7 -> Microsoft.Azure.WebJobs (= 2.1.0-beta4)
xxx.AzureFunctions -> Microsoft.Azure.WebJobs (>= 2.1.0-beta1)
Detected package downgrade: Microsoft.Azure.WebJobs.Extensions from 2.1.0-beta4 to 2.1.0-beta1. Reference the package directly from the project to select a different version.
xxx.AzureFunctions -> Microsoft.NET.Sdk.Functions 1.0.7 -> Microsoft.Azure.WebJobs.Extensions (= 2.1.0-beta4)
xxx.AzureFunctions -> Microsoft.Azure.WebJobs.Extensions (>= 2.1.0-beta1)
Detected package downgrade: Microsoft.Azure.WebJobs.Extensions.Http from 1.0.0-beta4 to 1.0.0-beta1. Reference the package directly from the project to select a different version.
xxx.AzureFunctions -> Microsoft.NET.Sdk.Functions 1.0.7 -> Microsoft.Azure.WebJobs.Extensions.Http (= 1.0.0-beta4)
xxx.AzureFunctions -> Microsoft.Azure.WebJobs.Extensions.Http (>= 1.0.0-beta1)
Package restore failed. Rolling back package changes for 'SE.AzureFunctions'.
Time Elapsed: 00:00:00.3832626
========== Finished =========
Package References in CS.PROJ
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup>
<TargetFramework>net461</TargetFramework>
<AssemblyName>SE.AzureFunctions</AssemblyName>
<RootNamespace>SE.AzureFunctions</RootNamespace> </PropertyGroup> <ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha6" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" /> </ItemGroup> <ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" /> </ItemGroup> <ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </ItemGroup> </Project>
I will try to provide you with the background of why you are experiencing the challenge you are, as well as propose a solution for you.
Background of the issue:
the reason you are experiencing this error is rooted in two places:
Microsoft downgraded the following packages (as I am sure the error message you received may have clued you into):
a. Microsoft.Azure.WebJobs from 2.1.0-beta4 to 2.1.0-beta1
b. Microsoft.Azure.WebJobs.Extensions.Http from 1.0.0-beta4 to 1.0.0-beta1
In .NET Core 2.0.0 Preview 2 - downgrade warnings have become errors. What this means is that they are configured to treat the warning NU1605 as an error. This is not publicized in their release notes, but if you look into the Property Pages of any project that was templated off the .Net Core 2.0.0 Preview 2 (like I suspect your project is), you would notice that under the Build project properties sheet, the warning NU1605 is now being treated as an error (see the Treat warnings as an error section). Let's stick a pin in that for now as we would need to dive into the project's property pages in the proposed solution below.
Proposed Solution (Note this is a work around!):
Yup, you've guessed it, you need to configure your project to NOT treat the NU1605 warning as an error. To do that, follow these steps:
Open the property pages of your project,
Go to the Build properties sheet
Scroll down to the Treat Warnings as errors section, and clear the NU1605 value from the Specific Warnings radio box section. (See screen grab below)
Save and rebuild your project (Nuget might actually attempt to restore the packages automatically when you save your project property pages changes --- if it doesn't do that or if the restore "fails", just rebuild the project and you should be fine)
Conclusions
I am sure Microsoft has its reasons for enforcing the downgrade warning NU1605 as an error, so don't take this recommendation of disabling this warning as an error as a blanket endorsement of this tactic; instead treat this recommendation as a work around to a problem that we are all bound to experience when we chose to work with pre-release or beta code.
My hope is that come the final release candidate, most of these type of dependency issues would have been worked out and such work arounds will not be necessary, but in the mean time, and to keep your alpha/beta/experimental development moving forward, this work around should do.
Hope this helps you and happy coding (ohh yea, Happy new year!)
Related
I am deploying an Azure Function called "Bridge" to Azure, targeting .NET 6. The project is referencing a class library called "DBLibrary" that I wrote, and that library is targeting .NET Standard 2.1. The Azure Function can be run locally on my PC without runtime errors.
When I publish the Azure Function to Azure, I see in Azure Portal a "Functions runtime error" which says:
Could not load file or assembly 'System.ComponentModel,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The system cannot find the file specified.
I do not target System.ComponentModel directly, and I don't see a nuget package version 6.0.0 for "System.ComponentModel" available from any nuget feed. Why is the Azure function looking for this version 6.0.0 of System.ComponentModel? If that version does exist, why can't the Azure Function find it?
Here are the relevant parts of the csproj for the "Bridge" Azure Function:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DBLibrary\DBLibrary.csproj" />
</ItemGroup>
</Project>
Here are the relevant sections of the csproj for the "DBLibrary" class library that is referenced by the Azure Function project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>
</Project>
I have tried setting _FunctionsSkipCleanOutput to true in the Azure Functions csproj because that was offered as a potential solution to nuget package resolution issues here:
https://github.com/Azure/azure-functions-host/issues/7061
That solution did not change the runtime error I saw in the Azure portal.
In my deployment pipeline, I was targeting functions runtime version ~2 for the Azure deployment when I should have been targeting version ~4 to support .NET 6. Changing to target version 4 of the Azure Functions runtime fixed the issue.
To find this setting on a deployed Function App, navigate to the Azure Portal (portal.azure.com) and search for the Function App resource's name there. Under the left navigation bar of the Function App, navigate to Settings > Configuration. After selecting the Configuration section, look for "Function runtime settings" at the top of the right pane to verify the Runtime version is "~4".
The function runtime version differences can be found here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp
This is the relevant part of the support table from the link above (as of February 2022):
Version
Support Level
Description
4.x
GA
Recommended runtime version for functions in all languages. Use this version to run C# functions on .NET 6.0.
If you have upgraded to .NET 6.0 you need to do the following to get past this error.
Update the cs proj to v4
Update the configuration in your function app in Azure to below
Update all the nuget packages for the solution
Clean the solution and then rebuild and it should work locally and should also work in Azure
The .net standard you are using 2.1 but ,Microsoft.Azure.Functions.Extensions can be support upto .NET Standard 2.0
You should add the below package to your function app and deploy to Azure again.
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-rc.2.20475.6
Please refer this GitHub issue and this MICROSOFT BLOG by #Jeremy for more information.
I have a .NETStandard 2.0 class library which is distributed via Nuget. It includes compiled native code libraries, specific to our target platforms. The .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>CoolProject</PackageId>
<Version>0.8.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AnotherCoolProject" Version="0.3.2" />
<PackageReference Include="YetAnotherCoolProject" Version="7.4.2" />
</ItemGroup>
<ItemGroup>
<None Pack="true" PackagePath="runtimes/win-x86/native/library32.dll" Update="library32.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Pack="true" PackagePath="runtimes/win-x64/native/library64.dll" Update="library64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Pack="true" PackagePath="runtimes/linux-x64/native/liblibrary.so" Update="liblibrary.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
This works great with .NET Core apps on all supported platforms. Lately, though, we discovered issues using this library from .NET Framework apps - the runtime libraries aren't always copied over to referencing projects, leading to System.IO.FileNotFoundException exceptions. This appears to be related to this issue:
https://github.com/Microsoft/msbuild/issues/1582
As a workaround, we want to add a Framework 4.6.1 target to the package. If I just update the project file above, removing the TargetFramework property and adding
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
the project builds without errors, and the nupkg is created with net461 and netstandard2.0 folders under lib/, but none of the runtime files are included anymore. I can verify this by unzipping the .nupkg, but it's pretty obvious as the package size goes from about 2mb to about 20kb. I've tried adding conditionals to the ItemGroup like
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
But still nothing. What am I missing here?
I have a project folder in Visual Studio Code on Debian 9 with a Solution file that references two projects. When opening the folder, a banner appears saying "Some projects have trouble loading. Please review the output for more details". Viewing the output shows the following exception for the main WebAPI project:
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
Failed to load project file '/home/aidan/Projects/WebApiDemo/WebApiDemo/WebApiDemo.csproj'.
/home/aidan/Projects/WebApiDemo/WebApiDemo/WebApiDemo.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
The unit test project returns a similar The SDK 'Microsoft.NET.Sdk' specified could not be found.
All other answers to this type of question refer to a global.json file, which I don't have anywhere in my project - this was a new .NET Core 2 project, and not converted from an older version. Adding global.json does nothing. It was working at first, and I'm not sure what I changed to make it break. I do have the dotnet folder in my $PATH. The project file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
Since I don't see any other explicit references to the SDK or its location in my project I'm stuck - any ideas what caused this to break?
Try to set MSBuildSDKsPath
export MSBuildSDKsPath=/opt/dotnet/sdk/2.2.105/Sdks
MS VS 2012
I have solution in tfs with enabled nuget packages restore. Every time when I build solution all my project files are cheked out with this changes:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
How to fix this behaviour?
As of NuGet v2.7, MSBuild-Integrated Package Restore has been deprecated and replaced with Automatic Package Restore.
See documentation on how to migrate your solution to the new feature: Migrating MSBuild-Integrated solutions to use Automatic Package Restore
To learn more about Automatic Package Restore see
NuGet Package Restore
Both articles discuss how this effects TFS integration.
Every time I create a new project, NuGet is adding a ton of packages that I don't want or need. I have tried uninstalling and reinstalling VS 2012, but somehow these packages keep coming back.
How do I completely remove them? If I uninstall NuGet, I get an error "NuGet.VisualStudio.Interop, Version=*, Culture=neutral ...
I then install NuGet, and all the old packages come back. I have no idea where this is being stored (registry?) but if I uninstall and reinstall Visual Studio, these should not be coming back.
Edit: I think I may have figured it out, but need confirmation. When I create a new, empty WebApplication, the packages are not added automatically. If I create a new, empty "Telerik MVC 4 Web Application", then I get the error shown in the picture below. I have set NuGet Package Manager to Allow NuGet to download missing packages and Automatically check for missing packages during build in Visual Studio, but I still get the error.
Edit/Solution: It turns out to be a problem with Telerik. I got this from support:
Is seems that you have ASP.NET and Web Tools 2013.1 installed.
Currently this update is not supported by our project templates. Until
we provide a support for ASP.NET and Web Tools 2013.1 I suggest you
convert an existing ASP.NET MVC Application to a Telerik UI for
ASP.NET MVC Application
This seemed to work.
The default list of NuGet packages are listed in the project templates.
You can find the templates here:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033
For example, if you choose MVC 4 Empty Web Application, the default packages are in the EmptyMvcWebApplicationProjectTemplate.11.cshtml.vstemplate file:
<packages repository="registry" keyName="AspNetMvc4VS11" isPreunzipped="true">
<package id="Newtonsoft.Json" version="4.5.11" skipAssemblyReferences="true" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.Razor" version="2.0.20715.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" skipAssemblyReferences="true" />
<package id="Microsoft.Net.Http" version="2.0.20710.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" skipAssemblyReferences="true" />
<package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" skipAssemblyReferences="true" />
</packages>
BTW: These packages are actually needed since MVC4+ is now installed entirely via NuGet.
Anyway, you can explore the other templates there and edit the .vstemplate files to add or remove the default packages.
For more information, look here:
https://docs.nuget.org/docs/reference/packages-in-visual-studio-templates
http://www.xavierdecoster.com/update-project-template-to-latest-nuget-packages
Hope this helps.