Project Code: https://github.com/sharpninja/csproj-convert
I'm trying to update an old F# project to .Net 5 and am receiving this error:
PS C:\GitHub\csproj-convert> dotnet run
System.ComponentModel.Win32Exception (2): The system cannot find the file specified.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Microsoft.DotNet.Cli.Utils.Command.Execute(Action`1 processStarted)
at Microsoft.DotNet.Cli.Utils.Command.Execute()
at Microsoft.DotNet.Tools.Run.RunCommand.Execute()
at Microsoft.DotNet.Tools.Run.RunCommand.Run(String[] args)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
Any idea what I'm doing wrong?
The issue is that it's a very old project specifying older components (from over 3 years ago) that just aren't compatible with .NET 5. Remove the following package references:
<PackageReference Include="FSharp.Core" Version="5.0.0" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.5" />
The first is not necessary (and is actually specified incorrectly; Update is used to override the reference pulled in by default for any F# project). The second is an old tool that pulls in a compiler from several years ago that used to be used in .NET Core 1.0 days.
Make sure you delete your obj folder as well so it re-generates a project.assets.json file on build and you should be good to go.
Related
Case
We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection
1) DependecyInjection
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
namespace xxxxx
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var services = builder.Services;
var configBuilder = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("local.settings.json", true, reloadOnChange: true)
.AddEnvironmentVariables() ;
ConfigureServices(services);
ConfigureAppSettings(services, configBuilder.Build());
ConfigureLogging(services, configBuilder.Build());
}
}
}
2) EF core 5.0 rc-1
https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-efcore-5-0-rc1/
Error
Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Packages
Following are the packages referenced
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.1.20451.14" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Troubleshooting
commenting the following line in startup.cs (Dependency injection) solves the problem
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
The Microsoft.Azure.Functions.Extensions depends on .net standard 2.0.
While the Entity Framework Core 5.0 RC1 will not run on .Net standard 2.0 platforms, it requires .net standard 2.1. So it could not find the Microsoft.Azure.Functions.Extensions.
For more details, you could refer to this article.
If you are using .NET core 3.1 or below that. Downgrade the NuGet packages of Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection.Abstractions to 3.x.x.
It's not supported in Azure Function v3, yet.
https://github.com/Azure/azure-functions-vs-build-sdk/issues/472
But, if you want to test it locally, I was able to run updating the DLL's in the Azure Function Core Tools directory:
C:\Program Files\Microsoft\Azure Functions Core Tools
I needed to replace/update these Dll's to use EF5 with my functions:
Dll's list
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Options.dll
Microsoft.Extensions.Primitives.dll
I switched my Azure function to an isolated process, which supports .NET 5.0. This only came about recently (March 2021). It looks like .NET 5.0 won't be supported in-process as far as I can tell (.NET 6.0 will be). There is a guide published here, I've listed the steps I took along with that for an existing project.
Steps
In .csproj, target .NET 5.0 (<TargetFramework>net5.0</TargetFramework>) and add <OutputType>Exe</OutputType>. Switch to the following packages:
Microsoft.Azure.Functions.Worker
Microsoft.Azure.Functions.Worker.SDK
Also replace Microsoft.Azure.WebJobs.Extensions.* with Microsoft.Azure.Functions.Worker.* ones.
In local.settings.json change runtime to: "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated".
Add Program.cs if you don't have one. Use the following:
public static class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services => {
// Add your services here...
})
.Build();
host.Run();
}
}
In your triggers, you'll need to update [FunctionName("Example")] to [Function("Example")], and update your using statements to Microsoft.Azure.Functions.Worker ones.
There some differences between .NET Core 3.1 and .NET 5.0 support listed at the bottom of that article here which is worth reviewing before making changes! Dependency injection is supported out the box though in the "normal" sense. I think it might be possible to rework Program.cs to use your existing startup.
Debugging
To debug the program, you can run the function using the Azure Function CLI and attach a Visual Studio debugger.
Open terminal in CSProj directory.
Run func start --dotnet-isolated-debug.
When the app runs, you need to look for the process ID, or PID. The line looks something like " Azure Functions .NET Worker (PID: ###)".
In Visual Studio. Debug > Attach to Process..., search by the PID in the previous step (dotnet.exe) and Attach.
Further reading
The documentation seems a bit sporadic, I also found another guide on developing and publishing .NET 5.0 Azure functions here.
There is this issue which sheds some more light on what is going on.
I have a .Net Standard 2.1 lib project with a service that is injected into my function app. In my solution the lib referenced:
Microsoft.Extensions.Options v5.0.0
After I changed the package version to 3.1.11, my function app ran successfully. In other words, if any project referenced by your function app has a reference to a .Net 5.0 package, it looks like you will get this exception if you are using DI.
Current versions in my function app:
Function app: .Net Core 3.1
Azure Functions Version: 3
Other libs: .Net Standard 2.1
I started with .Net 5.0 for the function app but apparently that is not supported for now:
.NET 5 support on Azure Functions
Hopefully this answer will be obsolete before too long but as of Jan 24, 2021 don't use .Net 5.0 projects or package references in your Azure function app solution/projects.
I cloned the repository at the G1ANT.Robot github page and opened G1ANT.Sdk.sln in VS Studio 2019 CE 16.1.5, Win10 Pro with latest updates. I left the default build properties as "Debug" and "AnyCPU". The following error can't be resolved, as I don't have the required files on my system:
Severity Code Description Project File Line Suppression State
Warning Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.CoreUtility, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. G1ANT.AddonTemplate
There are other errors, all seemingly related to dependencies on an earlier version or versions of VS (some I believe to be v14.0 dependent, some to be v15.0 dependent).
I do have the Microsoft.VisualStudio.CoreUtility available, but the version is 16.0 (i.e. VS 2019). In short, it appears that compilation may require an earlier version of VS than the one I have. Installing such an earlier version is not an option for me.
Thanks,
burque505
Yes, file /G1ANT.Sdk/G1ANT.Sdk/source.extension.vsixmanifest should be changed:
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,]" />
<InstallationTarget Id="Microsoft.VisualStudio.Pro" Version="[15.0,]" />
<InstallationTarget Id="Microsoft.VisualStudio.Enterprise" Version="[15.0,]" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.6.1,)" />
</Dependencies>
You can download the correct installation: https://github.com/G1ANT-Robot/G1ANT.Sdk/raw/master/G1ANT.Sdk.vsix
I believe it will help :)
When I set up a new F# project in Xamarin Studio with a reference to Suave I get an error.
Here are the steps to reproduce the error message:
Create a new solution in Xamarin Studio 6. Type: Console Project in F#
Add the Suave nuget package: Suave 1.1.2
Open Program.fs and add this line on the top of the file: 'open Suave'
After this the word 'open' is decorated with red squiggles and when I move the mouse pointer over it a little pop up appears with this message:
Error: Multiple references to 'FSharp.Core.dll' are not permitted
Why does this error messages come up and how do I remove it?
What I have noticed is that the installation of the Suave nuget package had also caused the installation of the FSharp.Core nuget pakage. Here is the resulting packages.conf file:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Core" version="3.1.2.5" targetFramework="net45" />
<package id="Suave" version="1.1.2" targetFramework="net45" />
</packages>
This happens because the Xamarin's F# project template by default references the local copy of FSharp.Core.
Removing the (duplicated) reference should fix the issue.
I just updated Xamarin Studio to ignore the local copy of FSharp.Core if the project contains a reference to a NuGet version. Should be released in XS 6.1 cycle 8.
I've got TFS doing some continuous integration builds. Today, it broke for one solution. It seems it can't find AutoMapper. All the other packages can be found just fine.
A couple relevant points:
None of the packages are in source control, we're letting TFS restore them.
We have an internal NuGet feed, but it doesn't seem to be a problem in other solutions, and in this solution we are still getting Entity Framework to restore - just not AutoMapper.
I tried removing and re-adding the NuGet Packages. No luck.
If I use Remote Desktop to connect to the build server and open the project in Visual Studio there, it restores the packages and builds fine.
I can build manually by executing D:\"Program Files"\"Microsoft Team Foundation Server 12.0"\Tools\Nuget.exe restore followed by msbuild MySolutoin.sln
Our TFS server is installed on our D:\ drive.
This is from the TFS Logs:
D:\Program Files\Microsoft Team Foundation Server 12.0\Tools\nuget.exe restore "C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.sln" -NonInteractive
Installing 'EntityFramework 6.1.3'.
Installing 'InternalPackage 1.0'.
Successfully installed 'InternalPackage 1.0'.
Successfully installed 'EntityFramework 6.1.3'.
Unable to find version '3.3.1' of package 'AutoMapper'.
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\MSBuild.exe /nologo /noconsolelogger "C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.sln" /nr:False /fl /flp:"logfile=C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.log;encoding=Unicode;verbosity=normal" /p:SkipInvalidConfigurations=true /m /p:OutDir="C:\Builds\1\MyCompany Web\FclQuoteWcfService\bin\\" /p:VCBuildOverride="C:\Builds\1\MyCompany Web\FclQuoteWcfService\src\FclQuoteWcfService.sln.vsprops" /dl:WorkflowCentralLogger,"D:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/230;IgnoreDuplicateProjects=False;InformationNodeId=12;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://ctidev2k8:8080/tfs/MyCompany;"*WorkflowForwardingLogger,"D:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;" /p:BuildId="9aa9f8af-c9b9-4d0a-ba06-7cc959231d8e,vstfs:///Build/Build/230" /p:BuildLabel="FclQuoteWcfService_20150330.2" /p:BuildTimestamp="Mon, 30 Mar 2015 20:40:07 GMT" /p:BuildSourceVersion="LFclQuoteWcfService_20150330.2#$/MyCompany Web" /p:BuildDefinition="FclQuoteWcfService"
Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException) Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
I've seen this too. It seems to be triggered as soon as NuGet package restore switches to the internal feed. Once it does this is doesn't switch back to the official nuget.org feed and continues to look for the packages on the internal feed.
Ensure both package sources are added to your NuGet.config file. Also ensure both sources are 'active'.
<configuration>
<packageSources>
<add key="nuget.org"
value="https://www.nuget.org/api/v2/" />
<add key="example.com"
value="http://example.com/feed/nuget/" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
</configuration>
See NuGet configuration file documentation.
Matt's answer put me on the right track but we don't use an internal feed so I had to do some more digging. This answer works, at least, for a project created in Visual Studio 2015 and built by TFS 2015.
In Visual Studio, open the NuGet package manager settings (Tools menu > NuGet Package Manager > Package Manager Settings). Choose "Package Sources" from the options list on the left.
Create the nuget.config file at the root of the solution. This should be the same folder location as your ".sln" solution file. Copy the following into the config file:
<configuration>
<packageSources>
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
</configuration>
Within the <packageSources> tag, create an <add key="" value="" /> entry for each source listed in the "Package Sources" options window. The key is the name of the source as shown above the URL, and the value is the URL itself. Include those listed in both "Available package sources" and "Machine-wide package sources". I did not create an entry for the local filesystem as it wasn't used in this solution. Based on the screenshot above, the complete config file now contains the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org"
value="https://api.nuget.org/v3/index.json" />
<add key="Microsoft and .NET"
value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
</packageSources>
<activePackageSource>
<add key="All"
value="(Aggregate source)" />
</activePackageSource>
</configuration>
After committing the nuget.config file to source control, TFS was able to download all the necessary NuGet packages and successfully build the solution.
In addition to Matt's answer, I'd like to highlight the following well-hidden stuff from the NuGet documentation:
NuGet config files are treated in the following priority order
(closest to the folder nuget.exe runs from wins), for example assuming
the solution directory is c:\a\b\c:
c:\a\b\c\.nuget\nuget.config - This file is only used for solution
level packages, and is not supported in nuget 3.0 - 3.4
c:\a\b\c\nuget.config
c:\a\b\nuget.config
c:\a\nuget.config
c:\nuget.config
User specific config file,
%AppData%\NuGet\nuget.config.
Or the user specified file thru option
-ConfigFile.
This could explain some weird behaviour in specific scenario's where a restore does or does not pick up a configured feed, depending on whether youre restoring with nuget 2.x or 3.x
Edit: and I found yet another reason why packages might not be detected:
I have package "A" with version 1.1.1.0 .
Prior 3.4 this command works well:
nuget install A -version 1.1.1.0
With NuGet 3.4 RC I get:
An error occurred while retrieving package metadata for 'A.1.1.1' from
source 'N'. An error occurred while retrieving package metadata for
'A.1.1.1' from source 'N'. Data at the root level is invalid. Line
1, position 1.
...
The client treats 1.1, 1.1.0, 1.01.0 and 1.1.0.0 as the same version
using SemVer rules. The reason non-normalized versions were special
cased in the past is because for v2 http calls the client would first
send the version string exactly as the user specified it
When I checked in the code, TFS 2013 built the solution automatically. It is okay in local VS 2013 but failed in TFS.
Here is the summary.
Summary
FTPProcessor | Any CPU
1 error(s), 56 warning(s)
$/xxxx/NewServiceHost/New-Branch/NewServiceHost/packageRestore.proj - 0 error(s), 0 warning(s)
$/xxxx/NewServiceHost/New-Branch/GenericWindowsServices.sln - 1 error(s), 56 warning(s)
C:\Builds\1\xxxx\FTP Processor (New)\src\.nuget\nuget.targets (71): The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Build.Tasks.v4.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Build.Tasks.v4.0.dll' or one of its dependencies. The system cannot find the file specified.
Other Errors
1 error(s)
Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException) Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Your TFS 2013 build server is using MSBuild 12.0 where CodeTasksFactory exists in Microsoft.Build.Tasks.v12.0.dll rather than Microsoft.Build.Tasks.v4.0.dll.
Ideally you should be doing the following:
1) Open your NuGet.targets file:
C:\Builds\1\xxxx\FTP Processor (New)\src.nuget\nuget.targets
2) Identify the task referencing the old DLL.
<UsingTask AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" TaskFactory="CodeTaskFactory" >
...
3) Then future proof it like so:
<UsingTask AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll" TaskFactory="CodeTaskFactory" >
...
As of VS2013,
you should be running MSBuild from C:\Program Files (x86)\MSBuild\12.0\Bin\
not from C:\Windows\Microsoft.NET\Framework64\v4.0.30319. See
http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx
source:http://gyorgybalassy.wordpress.com/2013/12/31/msb4175-the-task-factory-codetaskfactory-could-not-be-loaded/
it solved the issue for me.
After much research and trying a bunch of "hacks" I went on to understand the exact mechanics of nuget restore. It turns out, everything has changed since nuget 2.7+ and you're no longer required to include ".nuget" folder and the associated nuget.exe and nuget.target
To fix my build process and use the latest recommended approach, I did the following:
Move nuget.config to be with .sln file same folder path
Delete ".nuget" folder entirely
Delete references to that folder in .sln file
Delete following lines from any .csproj file
--
<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
--
This could take some time if your project solution has many files or you work on many projects built with Visual Studio 2013 and before.
The good news is, there's a powershell script that applies the above recursively on any folder:
https://github.com/owen2/AutomaticPackageRestoreMigrationScript/blob/master/migrateToAutomaticPackageRestore.ps1
In short, it reverses "Enable Nuget Package Restore", allowing the
newer package restore method to work.
In Visual Studio 2013, automatic package restore became part of the
IDE (and the TFS build process). This method is more reliable than the
older, msbuild integrated package restore. It does not require you to
have nuget.exe checked in to each solution and does not require any
additional msbuild targets. However, if you have the files related to
the old package restore method in your project, Visual Studio will
skip automatic package restore. (This behavior is likely to change
soon, hopefully it does).
You can use this script to remove nuget.exe, nuget.targets, and all
project and solution references to nuget.targets so you can take
advantage of Automatic Package Restore. It more or less automates the
process described here.
It will recurse through the directory you run the script from and do
it to any solutions that may be in there somewhere. Be careful and
have fun! (not responsible for anything that breaks)
A couple of good links on the subject:
http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore
I had a similar issue. We are forced into using the older msbuild that comes with the framework, rather than the v14 version that comes with visual studio 2015 because we build some old Delphi.net code. Our vcxproj files are triggering some automatic code analysis target which has a task that relies on Microsoft.Build.Tasks.v12.0.dll. I was able to override that task by copying and pasting it into the top of the vcxproj and tweaking the path to the dll. The original task can be found in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.Targets". So, in other words, you might be able to override the problem task in your project.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- override a task which we can't use with the old msbuild -->
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<EnvKey ParameterType="System.String" Required="true" />
<EnvValue ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
}
catch {
}
]]>
</Code>
</Task>
</UsingTask>