Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I actually apply the "dotnet try-convert" to files to convert to .net core?

Tags:

.net

https://github.com/dotnet/try-convert/ I downloaded this project, built it, but I'm not sure how to actually apply it to projects I want to convert? Might be a rather trivial question but I did poke around quite a bit and can't seem to figure it out.

Thanks!

edit: The readme does gives instructions on how to build and the options but I don't understand how to apply it to to the project. For example -p, --project < P > and I'm assuming the "P" is a placeholder for the file path.

So, I open the command prompt, and run try-convert.exe. Then, I input --project < C:/whatever/whatever > and hit enter. This should result in the file being converted? It's what I tried and it's not working. Is there something I'm missing?

edit edit: Maybe a visual would be easier to articulate my point:

From the README this this the command I'm trying to run

README

So I run try-convert.exe which is fine and dandy

Command Prompt

When I try to convert, No luck

Error

If someone could let me know what I'm doing wrong that would be great!

like image 462
mustang Avatar asked Dec 24 '19 21:12

mustang


People also ask

How do I use NET Core?

NET Core Application. In the middle pane on the New Project dialog box, select Console Application (. NET Core) and name it "FirstApp", then click OK. Visual Studio will open the newly created project, and you will see in the Solution Explorer window all of the files that are in this project.

Is .net6 .NET Core?

NET 6, though, is ASP.NET Core 6, a major upgrade of Microsoft's open source framework for building modern web applications. ASP.NET Core 6 is built on top of the . NET Core runtime and allows you to build and run applications on Windows, Linux, and macOS. ASP.NET Core 6 combines the features of Web API and MVC.

Can I install .NET Framework and .NET Core on the same machine?

NET Core installations are completely independent from the version of . NET Framework. In fact, you can actually install multiple version of . NET Core side-by-side on the same machine (unlike .


2 Answers

To upgrade all projects in a solution at once, rather than running try-convert multiple times (once for each project) you can use the following Powershell script in a command window, after navigating to your solution (or repository) directory:

$paths = Get-ChildItem -include *.csproj -Recurse
foreach($pathobject in $paths) 
{
   cd $pathobject.directory.fullName
   try-convert
}
like image 161
Greg Trevellick Avatar answered Oct 10 '22 01:10

Greg Trevellick


It's all described in the repository. You don't even have to clone it. You can easily install that as a dotnet global tool with:

dotnet tool install -g try-convert

Then restart the terminal and check if it was installed correctly with:

dotnet tool list -g 

Which lists all the tools and tells you what command to use. The help for try-convert is pretty useful, so you can get it with:

try-convert --help

Later you can try to run it on the whole solution which means in the folder where you have your .sln file. However it never worked for me if in at least one of the project I had a startup project like ASP.Net WEB API. In this case you need to run the tool on every single project manually. E.g.

try-convert -w .\<your-project-name>.csproj

And for the API project just create a new project targeting .Net Core and move all your controllers and other code there. The startup project is always most complicated for migration so it's not that easy to do it automatically.

like image 25
Tomasz Chudzik Avatar answered Oct 10 '22 00:10

Tomasz Chudzik