Build Error with pre-compiled Azure Function Library - c#

Recently, I converted an Azure Function that used a C# script (*.csx) to a pre-complied class library using the Visual Studio Studio Tools for Azure Functions. It builds successfully in Visual Studio 2017 (as well as running and debugging too).
I'd like to build this AF library via our CI process. However, when I run the command dotnet build locally it fails with the following error:
C:\Users\ray\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Microsoft.Azure.WebJobs.Host, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
The same error also occurs in our CI build.
Not sure why this error is occurring and how to resolve it. Is it the version of the dotnet CLI (I'm using v1.1)? Is it something else?

UPDATE 2018-01-08
According to a new answer by #theGRS https://stackoverflow.com/a/48156446/621827 this has been resolved.
Previous Answer
Here's what I've found.
dotnet msbuild uses the Microsoft.NET.Sdk.Functions .NETStandard 1.5 library which if you look at the dependencies on NuGet it doesn't use Microsoft.Azure.WebJobs
But if you use the Visual Studio 2017 msbuild it will use the .NETFramework 4.6 version of the library which includes Microsoft.Azure.WebJobs.
My suggestion is to use MSBuild for now.

I was having the same issue as well when running dotnet build, but no longer have this issue after updating Microsoft.NET.Sdk.Functions from 1.0.2 to 1.0.7.
Update to the latest version of this package in your Nuget package manaager and you should be able to run dotnet build again.

Related

docfx metadata step fails with error "Could not load SDK Resolver"

Whenever I try to build any documentation using docfx, I get the following error in the metadata build step that uses msbuild to analyze the xml comments in the code of the csprojs:
Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'C:\temp\docfxtest\docfx_project\src\src.csproj' with message: Could not load SDK Resolver. A manifest file exists, but the path to the SDK Resolver DLL file could not be found. Manifest file path 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\SdkResolvers\Microsoft.Build.NuGetSdkResolver\Microsoft.Build.NuGetSdkResolver.xml'. SDK resolver path: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll C:\temp\docfxtest\docfx_project\src\src.csproj
It seems that msbuild cannot be correctly resolved by docfx. Any idea how I could fix this?
Im using docfx version 2.56.5.0 on Windows and I also have VS Enterprise 2019 (16.8.2) and VS Build Tools 2017 (15.9.29) installed:
UPDATE:
I have now uninstalled the VS 2017 build tools completely and repaired the VS 2019 installation using the installer. I now get a different error when I run docfx. It seems that it can't find msbuild at all anymore.
Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'C:\temp\docfxtest\docfx_project\src\src.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found. C:\temp\docfxtest\docfx_project\src\src.csproj
Running msbuild -t:restore,build also shows that it can't find msbuild
'msbuild' is not recognized as an internal or external command
The targets are isntalled:
And so is the .NET Core workload:
Your Build Tool for VS2017 might have some problems due to some issues. The most issue is this:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll
Either you lost the dll or the dll is damaged.
Update
1) First, you should check whether you have installed NuGet targets and build tasks workload and net core build tools workload. If not, please install it.
2) Second, please delete bin and obj folder of your project and then try again.
You should use msbuild -t:restore,build to build your project.
3) Third, try to Repair from vs_installer for your build tool. It will repair the related dll. And then delete bin and obj folder, use build tool to test your project again.
Important:
VS2017 does not support net core 3.1. You should note that. It supports <=net core 2.1.
So if you still want to use Build Tool of VS2017 for your net core project, you should try the the above three steps and then target your project to net core 2.1.
Besides, if you start msbuild by CMD, I think you should check your environment variable PATH and check whether you have configured the msbuild.exe from Build Tool of VS2017 on it. Instead, you could add C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe. This way is for VS2019.
=================================================
Update 1
The problem is that you have already installed a docfx tool by choco command line.
At the beginning, I always thought that you used docfx.console nuget package on your project and just invoke docfx.exe from C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe under command line.
Regardless of the installation of docfx.console package on your project, if you installed docfx tool by choco command and then just invoke docfx.exe on command line, it used the local docfx.exe under C:\ProgramData\chocolatey\lib\docfx\tools\docfx.exe rather than the nuget package.
So the issue is that your local docfx.exe has some errors due to some issues. You should reinstall the docfx.exe by choco command choco uninstall docfx; choco install docfx.
Actually, directly use docfx.console nuget package on your project might be easier. From this link.
It already contains the generation step of the documentation by docfx.exe(from C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe) and will execute it automatically rather than run docfx.exe again manually.
I have completely uninstalled docfx using chocolatey (choco uninstall docfx) removed every folder named docfxfrom c:\ProgramData\chocolatey\.chocolatey\ and then reinstalled it (choco install docfx). After that, everything worked fine again. The file c:\ProgramData\chocolatey\lib\docfx\tools\docfx.exe.config contains a lot of msbuild related configuration. Maybe something was messed up there.

The reference assemblies for framework .NETCore, Version=v5.0 were not found

I have a UWP project that was created using Visual Studio 2017. It builds fine on this machine (machine 1).
However, when I copy the project over to a machine (machine 2) where I only have the Visual Studio 2017 Build Tools installed, and attempt to build it using MSBuild, I get the following error:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
(1126,5): error MSB3644: The reference assemblies for framework ".NETCore,Version=v5.0" were not found. To resolve this
, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framewo
rk for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assemb
ly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted
for the framework you intend. [<path_to_my_UWP_project>\UWP.csproj]
I suspect the need for .NetCore v5.0 arises from this line in my UWP.csproj file:
< PackageReference
Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.0.1"
/>
I do a nuget restore before I build on machine 2, and I can see that microsoft.netcore.universalwindowsplatform successfully gets restored under < C_Users_me >/.nuget/packages, and so does microsoft.netcore.
On machine 1 however, only microsoft.netcore.universalwindowsplatform gets restored but it still builds fine via Visual Studio.
Question: Why am I getting this error and how do I fix the problem?
I was getting the same error message. The resolution was to install the latest version of Visual Studio 2019. I had version 16.6 installed on my computer. I needed version 16.8 installed. Once I did the install, the error message went away.
Initial reason for this issue: I had received a VS C# solution from another individual. Apparently there was something in the solution that stated it required some library (.NETFramework v=5.0) which was not in 16.4 but was in 16.8.
The help instructions on the VS error message did not help; there is currently no .NETFramework, version=v5.0. There is only a .NET Core Version=5.0 or a .NetFramework Version=v4.8
This gitHub post lead me to the correct soltuion.
I was chasing the exact same issue but for all I could see, I had the right SDK installed. As it turned out, I had caused the issue myself by placing a global.json in the root directory with the SDK version pinned to 3.1.404.
dotnet was honouring the global.json settings and hence could not locate the reference assemblies for 5.0.
Removing the global.json fixed the issue for me.
You need to use Visual Studio 2019 16.8 Preview 2 or newer to use .NET 5 Preview 8. .NET 5 Download it here https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview
The reference assemblies for framework .NETCore, Version=v5.0 were not found
According to the error log, it seems you are missing the .NET framework SDK (. NET core, v5.0) on your machine 2. You can check the it from following directory:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v5.0
To install it, make sure you are install following individual components:
If you still have that error, please try to copy the directory C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v5.0 from machine 1 to machine 2.
Hope this helps.
The below steps worked for me.
In Visual Studio open View -> Terminal and enter: dotnet new global.json
Open the root folder of the solution and edit the newly created file "global.json" the exact name of the .net version installed must be entered.
To view all installed .net core sdk's , enter dotnet --list-sdks in command.
add the correct version to the global.json file, the right-click solution, and select Restore Nuget Packages or restart the visual studio.
The global.json will look like this
See you have Microsoft Visual Studio v16.8 or above.
To update the VS version -> Help -> Check for Updates
This error is displayed if the .NET 5.0 SDK is not installed. Be careful, you must download the proper sdk:
dotnet-sdk-5.0.401-win-x64.exe or dotnet-sdk-5.0.401-win-x86.exe depending on your installation (in the case of Visual Studio Code or your Windows) In the path https: // dotnet.microsoft.com/download/dotnet/5.0 you can download.
I had the same error message
enter image description here
1- Open Visual Studio Installer
2- Updat the version of Visual Studio 2019 to 16.11 or Upper
3- Restart your Project

MSBUILD throws error: The SDK 'Microsoft.NET.Sdk' specified could not be found

I'm trying to build a solution using msbuild command line and I keep getting this error:
error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
The version of msbuild is the latest from microsoft visual studio 2017 tools. I'm using Windows Server 2012 R2 and the project uses .NET Core 2.0.
This is the command that I'm using:
msbuild.exe /p:Configuration=Release /t:restore C:\Projects\MyProject.sln
Complete log:
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 9/16/2017 3:09:03 PM.
Project "C:\Projects\MyProject.sln" on node 1 (restore target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Release|Any CPU".
Project "C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj" (2) on node 1 (restore target(s)).
C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
Done Building Project "C:\Projects\MyProject.sln" (1) is building "C:\Projects\Kernel\Kernel.csproj" (restore target(s)) -- FAILED.
Build FAILED.
"C:\Projects\MyProject.sln" (restore target) (1) ->
"C:\Projects\Kernel\Kernel.csproj" (restore target) (2) ->
C:\Projects\Kernel\Kernel.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
0 Warning(s)
11 Error(s)
I encountered this error after playing around with .Net Core 2.0 installation and seemingly messing it up. I would get this same error for dotnet restore, dotnet build or dotnet msbuild. Essentially, anything involving .Net Core and msbuild.
The error occurred because the MSBuildSDKsPath environment variable was still pointing to the old .Net Core 1.1 SDK.
To fix the problem, I manually set the MSBuildSDKsPath environment variable to point to 2.0.0's SDK path, which, for me with x64, this was at: C:\Program Files\dotnet\sdk\2.0.0\Sdks.
Basically, if you have Sdk="Microsoft.NET.Sdk" in your .csproj, then a folder with the same name should exist at your MSBuildSDKsPath location.
You were probably missing some components when you installed the VS tools
Download and run Build Tools for Visual Studio 2019. (On the VS download page, go to Tools for Visual Studio 2019 and then click download Build Tools for Visual Studio 2019)
Select Modify on Visual Studio Build Tools 2019 or your instance.
Select tab Individual components and check .NET Core SDK component
for me the solution was to set the sdk version in the global.json file:
and specify the correct version which exists in the C:\Program Files\dotnet\sdk folder. The VS installer uninstalled the previous version of .NET Core 3.0.100 and installed new one 3.1.100 so I had to change it from:
{ "sdk": { "version": "3.0.100" }}
to
{ "sdk": { "version": "3.1.100" }}
For me updating Visual Studio Build Tools resulted in the 'SDK not found' error.
The solution: run Visual Studio Installer, modify the Visual Studio (Build Tools) installation, and make sure the following workload is selected:
I got this issue in Mac OS and while using docker container and Azure this occurs because docker bash overrides MSBuildSDKsPath so don't
change any code just quit and restart your IDE (visual studio Mac) and run it again
I got the same issue when I tried to install x64 .Net Core SDK installer. Even the following dotnet --info command shows me that no SDK is found.
So, try to install x86 .Net Core SDK installer. That can help you.
I had the same problem and found solution here:
https://github.com/aspnet/AspNetCore/issues/3624
Solution is to just have x64 or x86 version of sdk/runtime/hosting.
If you have both and if you use for example x86 version of dotnet.exe it won't see x64 versions of SDK installed.
Problem usually occures when you install hosting bundle because it includes both x86 and x64. Just uninstall one you don't use.
To anyone that, like me, run into this issue on Linux and found this thread:
This problem occurs, because your .bashrc config overrides MSBuildSDKsPath environment variable with outdated value (most likely it's a leftover after dotnet package update). To solve this:
Edit ~/.bashrc
Remove the line with MSBuildSDKsPath variable initialization, e.g.
export MSBuildSDKsPath="/opt/dotnet/sdk/2.2.108/Sdks/"
If you have previously worked with C# and it somehow stopped working:
For me updating to the latest version (probably of the build tools) with the "Visual Studio Installer" solved the problem.
I started getting this error after installing Visual Studio 2022 in Windows 10, when I opened up my solution. The solution contains a mix of .NET Framework 4.8 and .NET Standard 2.0 projects, and the error was on the .NET Standard 2.0 projects. I had previously Visual Studio 2019 and 2019 Build Tools installed.
The problem was that I had both x86 and x64 of dotnet installed, and both was in my systems PATH environment variable:
C:\Program Files (x86)\dotnet
C:\Program Files\dotnet
I did the following steps to fix this error:
Uninstalled VS2019
Uninstalled VS2019 Build Tools
Removed the x86 path from the environment variable
Removed the folder "C:\Program Files (x86)\dotnet" from my computer
Restarted VS2022
I think that the important part was to remove x86 from the environment variable. The other steps was just to "clean up".
I resolve the issue by installing the package directly form the Package Manager Console:
Install-Package NETStandard.Library -Version 2.0.3
Maybe you encountered the error after installing .NET core SDK 3.0. You have to check the environment variable MSBuildSDKsPath after every install of a new SDK. It must target the SDK you use to create your project. I use VS2017 with Windows 10.
For 2.2 SDK:
C:\Program Files\dotnet\sdk\2.2.104\Sdks
For 3.0 preview :
C:\Program Files\dotnet\sdk\3.0.100-preview3-010431\Sdks
The issue was occuring for me only when I tried to build the project with
dotnet build using VS2022 .
MsBuild on the same project was working fine.
What I did was:
restore the .net core runtime sdk - I was using 3.1 at the time.
Add both sdk paths in both Path vars, for the user and system, in that order:
Delete the MSBuildSDKsPath
P.s. I had this error while trying to run the coverlet coverage analysis
Had the same issue after I updated (snip) all VS installations on my windows machine a while ago. A restart of my PC resolved the issue.
I had this same issue, and it turned out the resolution for me was none of the above for me.
I was running the VS preview version with an older version of VS. I removed the Preview VS and then had to remove each of the environment variables by hand (i.e ANDRIOD_HOME, and .Net Maui vars, etc) and was back in business. Hope this helps someone out there who has installed VS Preview only to break the dev build environment.
Cause I had a lot of diffeculties finding the url for build tools, here it is :
https://aka.ms/vs/16/release/vs_buildtools.exe
Documenantion :
https://learn.microsoft.com/en-us/visualstudio/install/create-an-offline-installation-of-visual-studio?view=vs-2019
I encountered the same error and to fix it I installed .NET 6.0 SDK.
https://dotnet.microsoft.com/en-us/download/visual-studio-sdks
I only had .NET 7.0 SDK installed, and for whatever reason the project I was trying to use needed .NET 6.0 SDK.
I ran into this issue after installing .NET 7 to work with gRPC. After uninstalling .NET 7 the IDE was still looking for it. I deleted the empty C:\Program Files\dotnet\sdk\7 folder. I closed an opened the project it found the lastest .NET 6 installation.

Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc

An update occurred last night and now I find myself unable to do a ctrl + '.' for code suggestions in VS 2015. An error message comes up saying the following:
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I can still build and develop but this will be really annoying without this feature. I admit it, I am getting soft!
Anyone have a suggestion for fixing this bug?
As pointed out by #CaptainAmerica the solution is to update the CodeDom assembly from NuGet. One should point out how to do this in Visual Studio.
I found the solution here:
https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/
Basically, in the Visual Studio menu select:
Tools-> Nuget Package Manager -> Package Manager Console
In the console that appears at the bottom of Visual Studio run this command:
Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
If any of the options doesn't work, here is the detailed guide to handle this scenario....
First of all version is important. Notice the version mentioned in the error...
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
If you see above error it means that it's not able to find version 1.3.1. Now please create new VS project. No preferences, it can be just simple console application. Now once project template is ready, go to Package Manager and run following command with your specified version...
Install-Package Microsoft.CodeAnalysis -Version 1.3.1
This will install all packages. Let it complete. Once it's done. We don't need this newly created project at all. You can delete it completely. Seriously! you can delete it. We did this because we wanted that package installed at global nuget level. When you install something, nuget stores it at global level of your machine as well. Path will be something like this...
C:\Users\<<Your Windows User>>\.nuget\packages
You can know your path by following...
%USERPROFILE%\.nuget\packages
Now you will see your required Microsoft.CodeAnalysis.dll there in following folder...
C:\Users\<<Your Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45
Please note that above path contains version number (1.3.1). If your version is different, look into that version folder.
Now that you have dll with you, all that you need to do is add that dll to GAC. For that you will need GacUtil.exe
This file get installed along with Visual Studio already. You can search "GacUtil" in C drive. For me it's there on below path...
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
Now run command prompt as Administrator and navigate current directory to your path containing GacUtil. The run below command to install that dll in GAC.
gacutil
-i C:\Users\<<You Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45\Mi
crosoft.CodeAnalysis.dll
Basically providing path to dll we installed globally. It will show message on successful installation.
That's all! Now start your Visual Studio again and you will get this issue fixed.
I had the same problem with Visual Studio 2015 Update 2, to solve the problem globally for all solutions, update to Visual Studio 2015 Update 3. Here is a link: Download from here
I found this page and at the bottom of the page under "Compatibility with ASP.NET" it says that ASP.NET uses the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform to update the Microsoft.CodeAnalysis assemblies. So I updated the DotNetCompilerPlatform package from 1.0.0 to 1.0.3 and it works again! Yeah, life is good again!
To solve this problem for all solutions, I needed to install the assembly Microsoft.CodeAnalysis.dll directly to the GAC – Global Assemblies Cache.
I got the file Microsoft.CodeAnalysis.dll from C:/Users/[user]/.nuget/packages/Microsoft.CodeAnalysis.Common/1.3.2/lib/portable-net45+win8/Microsoft.CodeAnalysis.dll.
To install the assembly to the GAC, I used a PowerShell script from https://github.com/LTruijens/powershell-gac.
Finally, I managed to install the assembly to the GAC with the following command from PowerShell:
Add-GacAssembly [myPath]\Microsoft.CodeAnalysis.dll
I was also facing same issue. My visual studio 2015 version was 2.0. I upgraded it to version 3.
Issue got solved !!!
I was also facing same issue, Try installing Microsoft.CodeAnalysis.CSharp nuget package. And if its not resolved, check version of Microsoft.Net.Compilers in your project, I was having version as 1.0.0 which was causing issue so updated Microsoft.Net.Compilers nuget to v1.3.2.
Found solution here : Github discussion
I have solved the problem this way:
Update Visual studio 2015 to Update 3
from the menu chose View => Notifications => Visual Studio Update 3 and clicked the update button.
Today ! i got the same problem and i resolve it by restarting visual studio 2015 :)
I encountered this issue when trying to build someone's code from github.
I was opening it in VS 2019 but I also have VS 2022. Opening and building in VS 2022 just worked.
I fixed this issue by updating all Nuget Microsoft dependencies to v2.0.0. This was using VS 2017. I was using a preview version.
In my case, the error occurred after turning off Live Unit Testing and running tests manually.Some tests would fail with the above error message.
Going into Test --> Live Unit Testing --> Options and issuing "Delete Persisted Data" resolved the problem.
I fixed similar issue by deleting the .vs folder located inside the solution.
I found the missing assemblies in the NuGet package (After the first one was resolved there were mulitple otheres): https://www.nuget.org/packages/Microsoft.Net.Compilers/1.3.1-rc
Installed them using GacUtil from the Dev console.
Unfortunately the extensive solution with "nuget install/gacutil" here above couldn't work as the exact version of the dependency dll was not available.
The following solved my issue in our complex webform application was to perform within the solution in Visual Studio -> Tools -> Nuget -> console package manager
Update-Package -reinstall
In my case, I was getting this error because my Visual Studio Solution was trying to use TextTransform.exe during a pre-build step in one of the projects, but my local machine didn't have the TextTransform.exe at the path specified by my pre-build step and my first attempt at fixing that was to just copy TextTransform.exe from some other location to where Visual Studio expected it to be. That appears to have caused this problem, because TextTransform.exe has other silent dependencies.
My fix was to change the pre-build steps so instead of looking for the file at
C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe
it would instead look in the Visual Studio install folder which had a bunch of other files, presumably one of which was a peer dependency of TextTransform.exe
C:\Program Files\Visual Studio\Common7\IDE\TextTransform.exe
That seemed to fix things for me.
I got the same problem, I am using VS2017 and installed Microsoft.EntityFrameworkCore.SqlServer 3.1.8, while in my VS2017 .Net core version is 2.1
So I downgraded my Microsoft.EntityFrameworkCore.SqlServer to 2.1.1 and restarted the solution.
The warning was gone !!
I had similar errors in VS2019 after upgrading project to .Net 5 according to https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-50?view=aspnetcore-5.0&tabs=visual-studio.
error CS0006: Metadata file
'C:\Users\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll'
could not be found.
'C:\Users\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll' could not be founderror CS0006: Metadata file
The fix was to close and reopen VS 2019
Try adding Nuget Package Microsoft.VisualStudio.Web.CodeGeneration.Design to your project
This question is many years old and the answers are all fairly old as well. I only recently ran into a similar-enough issue that I feel sharing my experience here (although potentially not complete) is relevant.
D:\Code\C#\sdkrazortest>dotnet --version
6.0.401
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp1
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details.
Processing post-creation actions...
Running 'dotnet restore' on D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj...
Determining projects to restore...
Restored D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj (in 102 ms).
Restore succeeded.
D:\Code\C#\sdkrazortest>cd webapp1
D:\Code\C#\sdkrazortest\webapp1>dotnet build
MSBuild version 17.3.1+2badb37d1 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
REWRITECSS : error : [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
An assembly specified in the application dependencies manifest (rzc.deps.json) was not found:
package: 'Microsoft.CodeAnalysis.Common', version: '4.3.0-3.22415.1'
path: 'lib/netcoreapp3.1/Microsoft.CodeAnalysis.dll'
Build FAILED.
REWRITECSS : error : [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:10.32
I originally tried loading packages like the top comments here had suggested and realized this issue started happening shortly after install .net core 6. After seeing some SO comments on dotnet-aspnet-codegenerator being version-specific I tried to create my netcore3.1 app using an older version of the dotnet cli via global.json:
D:\Code\C#\sdkrazortest>type global.json
{
"sdk": {
"version": "3.1.403"
}
}
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp2
Getting ready...
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/3.1-third-party-notices for details.
Processing post-creation actions...
Running 'dotnet restore' on webapp2\webapp2.csproj...
Determining projects to restore...
Restored D:\Code\C#\sdkrazortest\webapp2\webapp2.csproj (in 187 ms).
Restore succeeded.
D:\Code\C#\sdkrazortest>cd webapp2
D:\Code\C#\sdkrazortest\webapp2>dotnet build
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.dll
webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.Views.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:09.91
While this isn't an answer for the new templates not just working for me.. it might help someone potentially get "unstuck" or be the catalyst for someone providing a proper answer.
You need to install NuGet package Microsoft.Net.Compilers.Toolset, but make sure you match the right .NET version. In my case I was targeting netcoreapp3.1 so max version could be 4.0.1.
My root cause was for MassTransit analyzers nagging they cant find Microsoft.CodeAnalysis package, eg. An instance of analyzer MassTransit.Analyzers.AsyncMethodAnalyzer cannot be created.
I think one of the possible reasons for this issue could be the incompatibility of the .NET Framework and certain NuGet package. In my case I have .NET Core 3.1 and Testcontainers 2.4.0. The error does not happen on my local machine but it keeps showing up in my GitHub Actions remotely. It goes away after I downgrade Testcontainers to 2.3.0. Later the NuGet package AspNetCore.HealthChecks.EventStore 6.0.2 causes the same issue but that gets fixed in minutes rather than in hours :)

UWP Build on Jenkins

I'm trying to build a C# UWP on Jenkins, however I'm getting the following error:
XamlCompiler error WMC1006: Cannot resolve Assembly or Windows Metadata file 'System.Runtime.dll'
Build tools 2015 and VS2015 are both installed on the Jenkins server, and the build script is targeting version 14 of MSbuild
A clean source code tree straight out of version control for a UWP app needs NuGet to run to find dependencies specified in the project.json files.
As a dev, this is something Visual Studio 2015 normally does for you.
On a build server, you will need to run the command-line NuGet 3.x executable so that all the dependencies are pulled down on your build machine before your build runs (MSBuild part).
Go to http://dist.nuget.org/index.html to get hold of the command-line NuGet.exe.
The command will have the form of nuget.exe restore [MyApp.sln].

Categories