{"id":13715,"date":"2017-08-08T00:00:00","date_gmt":"2017-08-08T05:00:00","guid":{"rendered":"https:\/\/centricconsulting.com\/post\/techtuesday-tips-upgrading-net-core-to-csproj-visual-studio-code_boston\/"},"modified":"2021-12-15T00:14:12","modified_gmt":"2021-12-15T05:14:12","slug":"techtuesday-tips-upgrading-net-core-to-csproj-visual-studio-code_boston","status":"publish","type":"post","link":"https:\/\/centricconsulting.com\/blog\/techtuesday-tips-upgrading-net-core-to-csproj-visual-studio-code_boston\/","title":{"rendered":"#TechTuesday Tips: Upgrading .NET Core To .csproj in Visual Studio Code"},"content":{"rendered":"

Learn the steps to upgrade your\u00a0.NET core to SDK Preview3 or 1.0.1+ version – and debug your application in Visual Studio Code.<\/em><\/h2>\n

If you use .NET Core SDK 1.0.0-preview3-{buildnumber} , .NET Core no longer uses project.json to handle project and framework references.<\/h4>\n

Instead, it has moved to a more general approach, using a .csproj file. One of the main reasons to migrate to .csproj is to allow your\u00a0.NET Core code to interop with existing\u00a0.NET code.<\/p>\n

According to the Microsoft .NET Core team:<\/a><\/p>\n

W<\/em>hen we started building\u00a0.NET Core and ASP.NET Core it was important to have a project system that worked across Windows, Mac and Linux and worked in editors other than Visual Studio. The new project.json project format was created to facilitate this. Feedback from customers was they loved the new project.json model, but they wanted their projects to be able to work with existing\u00a0.NET code they already had. In order to do this we are making\u00a0.NET Core become\u00a0.csproj\/MSBuild based so it can interop with existing\u00a0.NET projects and we are taking the best features of project.json and moving them into\u00a0.csproj\/MSBuild\u2026<\/em>\u201d<\/p>\n

To upgrade, there are multiple steps. In fact, in Visual Studio Code, there are additional steps.<\/p>\n

In our #TechTuesday Tips series, we want to show you the\u00a0four steps (five for some)\u00a0to upgrade from project.json in Visual Studio Preview for Mac.<\/span><\/strong><\/p>\n

#1 Compiling Your Application<\/h3>\n

Those of you who feel adventurous, had an already working\u00a0.NET Core or ASP\u00a0.NET Core application and decided to migrate to the latest\u00a0.NET Core SDK (or at least Preview3), you will notice that your application no longer compiles when you debug the application in Visual Studio Code or run:<\/p>\n

dotnet build<\/strong><\/p>\n

\n
\n
\n
\"\"

Fig 1. MSBuild\u00a0error<\/em><\/p><\/div>\n<\/div>\n<\/div>\n<\/figure>\n

As you can see, the error is now a MSBuild error. This happens because your application has project.json instead of the new *.csproj file that MSBuild understands, so what can we do? Well the answer is pretty simple, we have to run one command from\u00a0.NET Core Command Line Tools.<\/p>\n

#2 Migrating Your Application<\/h3>\n

The command that will take care of converting your project.json project file into *.csproj project file is:<\/p>\n

dotnet migrate<\/strong><\/p>\n

Migrate command will create a backup folder and will place your project.json file here . You can opt to not create a backup folder by choosing the skip-backup option.<\/p>\n

For a list of available options use:<\/p>\n

dotnet migrate \u2014 help<\/strong><\/p>\n

NOTE: If you want to update your\u00a0.NET Framework and\u00a0.NET Standard version (CLR) make sure to update your project.json file\u00a0before running the migrate command<\/strong>\u00a0and update netcoreapp to 1.1 and Microsoft.NETCore.App to 1.1.1<\/em><\/p><\/blockquote>\n

\n
\n
\n
\"\"

Fig 2. Updating\u00a0.NET FX and\u00a0.NET\u00a0Standard<\/em><\/p><\/div>\n<\/div>\n<\/div>\n<\/figure>\n

After you run the migrate command, you will notice – if you didn’t choose the skip-backup option – a new folder called backup that contains your project.json file. You will also notice that a new file created – at the root of your project – has a .csproj extension. This is the file that MSBuild looks for to compile your project.<\/p>\n

Now that we have the missing file created, MSBuild should no longer complain and our project is supposed to compile successfully. But we might not be correct.<\/p>\n

#3 Unsuccessful Compilation, Again<\/h3>\n

If you run the build command:<\/p>\n

dotnet build<\/strong><\/p>\n

You\u2019ll notice that your application compiles successfully . (I<\/em>f you are on a Mac or Linux, you might need to run the command using elevated rights. If you find yourself in this situation, try to run:\u00a0<\/em>sudo dotnet build<\/strong>)<\/p>\n

Now that we have a successful compilation, we can execute:<\/p>\n

dotnet run<\/strong><\/p>\n

Copy the URL on your browser and you\u2019ll see that your application works as expected.<\/p>\n

\n
\n
\n
\"\"

Fig 3. Compiling and running the application through command\u00a0line<\/em><\/p><\/div>\n<\/div>\n<\/div>\n<\/figure>\n

Now, let\u2019s debug the application using Visual Studio Code, it should work right? Well\u00a0\u2026 it won\u2019t.<\/p>\n

You\u2019ll see that MSBuild complains again that the project file does not exist. But didn\u2019t we just migrate our project and create the project file?<\/p>\n

Well, it turns out that Visual Studio Code uses two files to compile and run the application . These two files are located under\u00a0.vscode folder. The files: tasks.json and launch.json.<\/p>\n

#4 Updating Visual Studio Code Files<\/h3>\n

Let\u2019s open\u00a0tasks.json<\/strong>\u00a0file first, locate the reference to project.json and update it to point to your new .csproj file.<\/p>\n

Finally, if you updated the framework version – in project.json before running\u00a0dotnet migrate<\/strong> – open\u00a0launch.json<\/strong>\u00a0and modify the program property.<\/p>\n

Make sure to update the path from netcoreapp1.0 to netcoreapp1.1. Otherwise, your application will run using the previously compiled assembly and you might be wondering why your latest updates are not reflected.<\/p>\n

#5 File Access Error<\/h3>\n

If you followed all the steps and you get a file access error when you want to debug your application, then you will have to grant read\/write access to your folders . Or run Visual Studio as an Administrator.<\/p>\n

If you are using OSX:<\/p>\n

    \n
  1. Right click on your project folder<\/li>\n
  2. Click on Get Info<\/li>\n
  3. Under Sharing & Permissions for Staff select Read & Write<\/li>\n
  4. Click on the lock icon, enter the user and password of an admin account<\/li>\n
  5. Click on the gear icon at the bottom and click on Apply to enclosed items<\/li>\n<\/ol>\n

    Now debug your application and Voila!<\/em>\u00a0Visual Studio Code can now debug your application.<\/p>\n

    \n
    \n
    \n
    \"\"

    Fig 4. Grant read and write access to your\u00a0folder<\/em><\/p><\/div>\n<\/div>\n<\/div>\n<\/figure>\n

    Originally published on Medium<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"

    Learn the steps to upgrade\u00a0.NET core application\u200a \u200ato SDK Preview3 or 1.0.1+ version\u200a – \u200aand properly debug your application in Visual Studio Code.<\/p>\n","protected":false},"author":171,"featured_media":25300,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_oasis_is_in_workflow":0,"_oasis_original":0,"_oasis_task_priority":"","_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","footnotes":""},"categories":[1],"tags":[],"coauthors":[],"acf":[],"publishpress_future_action":{"enabled":false,"date":"2024-08-04 12:00:47","action":"change-status","newStatus":"draft","terms":[],"taxonomy":"category"},"_links":{"self":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/posts\/13715"}],"collection":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/users\/171"}],"replies":[{"embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/comments?post=13715"}],"version-history":[{"count":0,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/posts\/13715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/media\/25300"}],"wp:attachment":[{"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/media?parent=13715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/categories?post=13715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/tags?post=13715"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/centricconsulting.com\/wp-json\/wp\/v2\/coauthors?post=13715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}