1

I was looking for a way to execute a .NET application on Linux and I discovered dotnet.

Preface

I was able to configure dotnet on Ubuntu 17.10.1 (Artful Aardvark), so I tried to create a simple .NET application using this command:

dotnet new console -o hwapp

And this worked well. The command has created a simple Hello, World! application inside the hwapp folder. For testing, if this works, I execute:

cd hwapp
dotnet run

This has printed "Hello, World!" and that's fine because all are working good.

The problem

I created a console application using Visual Studio 2017. This application is essentially the same created with dotnet and contains a simple "Hello World".

I pass it to Ubuntu, specifically inside the console folder, and then I execute this command:

cd console
dotnet run

but, I unfortunately get this warning message:

/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NetFramework,Version=v4.6.1" 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 framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/home/user/console/ConsoleApp1.csproj] The build failed. Please fix the build errors and run again.

I searched for this error on the Internet and I discovered that the installed .NET framework is not compatible with the application version, so I tried to compile the application to a less version of .NET framework such as "4.5", but I got the same error.

I also compared the .csproj file of the console application created using dotnet with the Visual Studio console application. The first has this structure:

<Project Sdk="Microsoft.Net.Sdk">
   <PropertyGroup>
       <OutputType>Exe</OutputType>
       <TargetFramework>netcoreapp2.0</TargetFramework>
   </PropertyGroup>
</Project>

Visual Studio console (.csproj):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{1E8D1AE9-C1A2-48D5-B183-3D958885A3BB}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

How can I fix this?

6
  • 2
    The one that works is targeting .net core, which will work cross platform. The one you created in visual studio is targeting the full blown .net 4.6.1 framework, which is not cross platform Commented Apr 19, 2018 at 19:10
  • @mituw16 I had imagined it. So I suppose the I can't run application developed with Visual Studio using dotnet or other utility on Linux, right? Basically I was looking for a way that would allow me to run a console application every hour, using a cron or something like, so I had thought about Linux, but at this point I think it's only possible using IIS, right? Commented Apr 19, 2018 at 19:14
  • 2
    No, you can run apps created with visual studio on linux, you just have to make sure you're targeting the right framework, in this case .net core, when creating the project Commented Apr 19, 2018 at 19:16
  • @mituw16 +1 for you, didn't noticed that I have to install the SDK on my VS, I'll try, thanks :) Commented Apr 19, 2018 at 19:18
  • no problem ! :) Commented Apr 19, 2018 at 19:20

1 Answer 1

1

You have to select ".NET Core" in the Visual Studio project selection, not the .NET Framework which is the old technology.

Tutorial: Create a .NET Core console application using Visual Studio

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.