dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.06k forks source link

dotnet cli does not run sln solution from Visual Studio #7767

Closed joelpresence closed 4 years ago

joelpresence commented 7 years ago

Steps to reproduce

We have a solution MyServer.sln which is a socket server that is a Visual Studio console app. It was created in Microsoft Visual Studio 2015 (but I think the sln file is 2012 format). I can run this app just fine in Windows and macOS (using Visual Studio for Mac).

However, we want to build and deploy this server as a dotnet core app so that we can run it inside Ubuntu linux in a Docker container using one of the official Microsoft docker containers.

However, although I can run this app using the play button within Visual Studio for Mac on macOS, I cannot run it on the macOS terminal commandline. How do I do this? Or alternatively, how can I create, from a VisualStudio .sln file, the needed project files to run the app with the dotnet cli?

# After compiling with Visual Studio for Mac

bash> dotnet MyServer.ConsoleHost/bin/Debug/MyServer.ConsoleHost.exe

A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in '/Users/joel/src/MyPlatform/Platform/MyServer.ConsoleHost/bin/Debug'.

# No MyServer.ConsoleHost.dll is generated by Visual Studio for Mac, so I can't see how to run that

So the question is, given a regular old Visual Studio .sln solution that people are using to develop a console app in Windows, how do I use dotnet core to build and run this for Linux or macOS from a headless terminal command line.

I don't want to create project.json file since MS is moving away from those and I'm not sure how. Is there some way to magically use the .sln file from dotnet cli to build for execution by dotnet cli?

Also, when I try to dotnet msbuild I get tons of errors about

/usr/local/share/dotnet/sdk/1.0.0-rc4-004771/Microsoft.Common.CurrentVersion.targets(1111,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.

Note that the MyServer.sln solution only uses basic dotnet core stuff. It doesn't use any Windows-specific stuff. It is a sln file because it was extracted from a larger sln that builds a Windows game but we extracted some of the common code to build the server.

Expected behavior

I should be able to build and run a regular old Visual Studio sln solution using dotnet cli on macOS and Linux.

Actual behavior

Doesn't work.

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc4-004771)

Product Information: Version: 1.0.0-rc4-004771 Commit SHA-1 hash: 4228198f0e

Runtime Environment: OS Name: Mac OS X OS Version: 10.12 OS Platform: Darwin RID: osx.10.12-x64 Base Path: /usr/local/share/dotnet/sdk/1.0.0-rc4-004771

joelpresence commented 7 years ago

I’ve tried dotnet build but I haven’t tried the run with the —project option. I’ll try that in the morning, thanks.

On Feb 16, 2017, at 6:56 PM, Marc Vertido notifications@github.com<mailto:notifications@github.com> wrote:

Have you tried dotnet build or dotnet run --project MyServer.ConsoleHost.csproj (assuming that's the csproj name)?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/dotnet/cli/issues/5747#issuecomment-280535546, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALf8WQCU6XOj3TuluNgIPUvJi0FtDDxCks5rdQxigaJpZM4MDsWI.

livarcocc commented 7 years ago

Are you trying to build/run the solution or are you ok if you build and run a particular project in that solution?

If you are running into issues when building/running a project, it would be useful if you could share the csproj file here so that we can see if it is compatible with the CLI.

The CLI only supports the new csproj format and won't work with legacy ones.

Since we haven't heard back in a while, I am closing this issue. If it is still a problem for you, please re-activate with additional information.

StefH commented 7 years ago

I have the same issue in my project (https://ci.appveyor.com/project/StefH/simmetrics-net/build/1.0.2.3 / https://github.com/StefH/SimMetrics.Net/blob/_vs2017/appveyor.yml)

I get the error message like:

C:\projects\simmetrics-net\.dotnetcli\sdk\1.0.1\Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v2.0" were not found.  . . .
livarcocc commented 7 years ago

@StefH this is for a project targeting .NET framework 2.0, which is not supported in the new tooling.

StefH commented 7 years ago

But in VS2017 the project compiles fine for all frameworks. So how to fix this in AppVeyor and Travis builds???

sathesh-pandian commented 6 years ago

Any updates on targeting .NET framework 2.0? i have seen people migrated .NET framework 2.0 apps in DotNet core and got struck like me.