The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded - azure

I'm trying to publish a newly created asp.net 4.6 web project to Azure web apps and receiving the following error:
remote: D:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly D:\home\site\repository\packages\Microsoft.Net.Compilers.1.0.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [D:\home\site\repository\WebApp\WebApp.csproj]
Everything builds fine via Visual Studio 2015 on my local machine. I thought Azure web apps were all set to support VS 2015 RTM upon release, but it would appear they do not have MSBuild 14.0 installed. Is there a work around or a roadmap for this problem?

Here was the fix for me.
Using Nuget Package Manager, remove these two packages if referenced:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
After that, run a rebuild. This ensured that the build was not trying to use a specific build exe. Click here for the
Diff against previous revision

In my case I have to edit my .csproj file and find below lines and delete them
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
Now everything is fine,

Azure Web Apps doesn't support ASP.NET 4.6 yet. It's on it's way though, so stay tuned.

Related

Build error Could not load file or assembly Microsoft.CodeAnalysis

We have a .net core 3.1 solution, which we are able to compile (using Visual Studio 2019) and publish. We gave the solution to our team which is setting up the deployment process. While trying the build (linux container) they are seeing the below error:
CommonLib -> /srv/jenkins_work/DSS/ewcms/CMS/CommonLib/bin/release/netcoreapp3.1/CommonLib.dll
CSC : error CS8032: An instance of analyzer Microsoft.EntityFrameworkCore.InternalUsageDiagnosticAnalyzer cannot be created from /var/lib/jenkins/.nuget/packages/microsoft.entityframeworkcore.analyzers/5.0.9/analyzers/dotnet/cs/Microsoft.EntityFrameworkCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [/srv/jenkins_work/DSS/ewcms/CMS/Microsoft.EntityFrameworkCore.UnitOfWork/Microsoft.EntityFrameworkCore.UnitOfWork.csproj]
The file mentioned Microsoft.EntityFrameworkCore.Analyzers.dll is there in the folder mentioned in the error. other projects in the same solution have this as a warning, but this particular project shows it as an error.
Reading online many said to install Visual Studio, but that is something they said they can not do in the container, is there another way to get around this issue? Or something in particular we need to look at in that project which is causing and error rather than a warning?
After some investigation, turned out that project had the setting:
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
which was not there in the other projects, which were showing it as warnings only. Changed this to false and this project is also going through now, it comes up as a warning and allows the build to go through.

Azure Function - Could not load file or assembly

Im running an Azure Function .NET Standard 2.0 and get following error:
An exception of type 'System.IO.FileLoadException' occurred in Function.dll but was not handled in user code
Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=9.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
The assembly file exist in the bin/debug folder. Been reading some threads about this but without a solution (https://github.com/Azure/azure-functions-core-tools/issues/322#issuecomment-352233979), anyone know what to do?
I'm using code from another .NET Standard 2.0 project but all my projects have a reference to Microsoft.WindowsAzure.Storage 9.2.0.0 and that nuget package installed.
Thanks!
You can add reference below to downgrade your storage reference explicitly.
<PackageReference Include="WindowsAzure.Storage" Version="8.6.0" />
See this issue comment.
This restriction (like many of the other assembly version restrictions we had with other extensions) is a temporary issue and will be addressed in upcoming preview releases.
This issue has been fixed in latest host 2.0.11888, but built cli(tools to run functions) is not available yet.
Update
2.0.11888 has been available to VS users.

TFS Tests do not match framework settings

I am attempting to move a solution from TFS 2012 to TFS 2018 SP2RC2 but I can't get the unit tests to run correctly. All projects have been re-targeted to 4.7.1 and are built as x86 platform. We have a testsettings file that supplies nothing but deployment items. I am using the new VSTest Platform Installer task (as directed by MS) and the VS Test Task. At the start of the test run I get the following message:
Test run will use DLL(s) built for framework .NETFramework,Version=v4.5 and platform X86. Following DLL(s) do not match framework/platform settings.
So all of the test are skipped as they target 4.7.1. Where is this 4.5 setting coming from? I cannot find it specified anywhere and can't figure out how to change it.
There is a /Framework: parameter that you can specify to VSTest.
In your case, you should specify /Framework:.NETFramework,Version=v4.7.1
See more at https://msdn.microsoft.com/en-us/library/jj155796.aspx?f=255&mspperror=-2147217396
To add this parameter in a Azure DepOps yaml pipeline, use the otherConsoleOptions argument
- task: VSTest#2
otherConsoleOptions: '/Framework:.NETFramework,Version=v4.7.1'
The fix I found for this in Visual Studio is way easier than I thought:
Exit all instances of VS
Open your project folder in Windows Explorer, find the .vs folder, delete it
Restart VS, the folder rebuilds itself, tests work again.
Apparently there are some settings that the NUnit plugin stashes in this folder and they are in binary so you can't edit them. This happened to me after I updated to NUnit3TestAdapter version 3.17.
I had trouble running a test project developed on another machine where no tests where able to be run using the MSTest test runner. In addition to message in your question I also got the messages:
Make sure that test discoverer & executors are registered and platform
& framework version settings are appropriate and try again.
Discover test finished: 0 found
In my case I resolved it by unloading and updating the .csproj file adding the following import directly under the root Project tag.
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
Hope this answer will help save you some time.
I got this error using Visual Studio 2019 with NUnit 3.12.0:
Test run will use DLL(s) built for framework
.NETFramework,Version=v4.5 and platform X86. Following DLL(s) do not
match framework/platform settings.
Project.UnitTests.dll is built for Framework 4.5.2
and Platform AnyCPU.
Installed NUnit3TestAdapter 3.13.0 and then everything started working. Did not need to modify Framework version or CPU settings.
Had the exact same issue as Bill, working on legacy code in VS2019, nothing else had worked. I simply changed the Run Settings to use the Auto Detect.
In the menu go to Test -> Configure Run Settings -> Auto Detect runsettings File
For me skipping tests in local VS2022 run was related to testsettings file. I deleted .vs folder of my project then selected
Test ->Configure Run Settings -> Select Autodetect run settings file
After that I can debug unit tests
TLDR: If you use *.runsettings file for your test projects, try removing TargetFrameworkVersion node
I had similar problem but with .Net Core
Test run will use DLL(s) built for framework
.NETFramework,Version=v4.0 and platform X64. Following DLL(s) do not
match framework/platform settings. MyProject.Tests.dll is
built for Framework .NETCoreApp,Version=v3.1 and Platform AnyCPU.
Turns out there was another problem. For my other .NET Framework test projects I had defined *.runsettings file
And in this file I had
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Parameters used by tests at runtime -->
<TestRunParameters>
<Parameter name="ConnectionString" value="Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True" />
</TestRunParameters>
<RunConfiguration>
<!-- Framework35 | [Framework40] | Framework45 | FrameworkCore10-->
<TargetFrameworkVersion>Framework40</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
Supported values for TargerFrameworkVersions based on https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2019
are:
FrameworkCore10 for .NET Core sources, FrameworkUap10 for UWP-based
sources, Framework45 for .NET Framework 4.5 and higher, Framework40
for .NET Framework 4.0, and Framework35 for .NET Framework 3.5.
But for Core 3.1, FrameworkCore10 doesnt work!
So I removed node TargetFrameworkVersion completely
I had the same problem in VS 2019 on a legacy project.
Restarting Visual Studio did not help, nor did build as Release then rebuild as Debug, nor did deleting the .vs folder. I did those things and still was unable to run tests, getting a message like the OP's during test detection each time. I mention these here for completeness.
I deleted the LocalTestRun.testrunconfig file and the *.vsmdi file from Solution Explorer, cleaned and rebuilt the solution, and the unit tests worked again.
I was running into the same issue with the Visual Studio Test Task version 2 in an Azure Devops 2019 pipeline after a .csproj test project was upgraded from .NetFramework 4.6.1 to .NetCore 3.1.
The fix for us was to be more specific when specifying the test files. The default of **\*test*.dll was finding several other assemblies with "test" in their names that didn't exist before the upgrade. Using an explicit **\<MyTestAssemblyName>.dll fixed the issue.

Azure continuous deployment error Could not load file or assembly Microsoft.WindowsAzure.Packaging

Out of nowhere I started getting this error when I try to deploy my project to cloud service (using continuous deployment and hosted build controller.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure Tools\2.5\Microsoft.WindowsAzure.targets (2917): Could not load file or assembly 'Microsoft.WindowsAzure.Packaging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I found this SO question, but it didn't help me.
Also I noticed I didn't even have folder:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\
I only have v10.0, v11.0, v12.0, so I manually created v14.0 and copied folder Windows Azure Tools form v12.0 but it didn't help.
EDIT
I've updated Azure tools to 2.6 but the problem and error message remains the same.
How can I fix this ?
I had the same error occurring today on Visual Studio Online's Host Build Controller. I assume you are using the same thing by your talk of Azure & Continuous Integration.
I noticed that they just released Azure SDK 2.6 support on the build controller in the last day or so. I feel that this may have somehow caused the problem.
I updated my cloud project to use 2.6, checked in, and everything was fine again. Some ccproj details:
<PropertyGroup>
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.6\</CloudExtensionsDir>
</PropertyGroup>
do you updated your Azure SDK for .NET to 2.5.1?
I have experienced this issue before when I updated the Azure SDK for .NET to 2.5.1
Microsoft has just recently release Azure SDK for .NET version 2.6 and I suggest you should try this. I believe this should solve your problem.
"try adding /p:GenerateBuildInfoConfigFile=false to your msbuild arguments in addition to /p:VisualStudioVersion=12.0, that has helped others workaround that same issue."
from here: https://social.msdn.microsoft.com/Forums/en-US/fc434580-cf81-44eb-9382-cd1b9fc9583a/microsoft-azure-sdk-v26-issue-with-cloud-builds?forum=TFService
Update Azure SDK to version 2.6 and after, update your Azure project's Application.
You can do this within the project's properties, by clicking the button to update Microsoft Azure Tools version from 2.5.1 to 2.6.

Issue with ReportViewer on Windows Azure websites (WAWS)

In one of my project i have used reportviewer control to display reports on web pages and at time of uploading on Azure I have followed the steps mentioned here
After uploading when i runs that report web page then it's giving me below error
An error occurred during local report processing.
The definition of the report 'Reports\Report1.rdlc' is invalid.
An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.ReportViewer.ProcessingObjectModel, >
Version=10.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The system cannot find the file specified.
What should be cause of this?
Update:
I have added following 2 dlls as shown in below snap
Microsoft.ReportViewer.Common.dll (10.0)
Microsoft.ReportViewer.WebForms.dll (10.0)
After long research i found solution of my problem from this link
The problem with missing reference of below dlls
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.RevportViewer.DataVisualization.dll
but after instaling i could not found those dlls in C:\Windows\Microsoft.NET\assembly\GAC_MSIL
But there is assembly files available in this path C:\Windows\assembly
then i have added those dlls using VS2010 directly as shown in below fig.
And it's worked!
What is the version of ReportViewer you have used in this project and would you please specify how many and which one Reference DLL you have included in your project? This will help to ensure that you have included all the DLL properly in your project. You must use Report Viewer SP1 which is compatible with Azure DB, and the same SP1 language pack.
I would suggest FTP to your website and verify that you do have all the DLL uploaded correctly as you configure in your project. This is the best way to check in Windows Azure Websites if all the configured files made it to file server.

Resources