LoginSignup
2
1

More than 1 year has passed since last update.

Visual Studio Codeでdotnet 3.x系のプロジェクトを開くとエラーCS0246やCS0518が出る問題の対処

Last updated at Posted at 2020-05-15

はじめに

プロジェクトのTargetFrameworkにnetcoreapp3.0やnetcoreapp3.1を指定した場合に、Visual Studio Codeでプロジェクトを読み込むとCS0246やCS0518が発生する問題への対処方法です。

CS0246_CS0518.png

omnisharp-vscodeの対応方法スレッド

下記のスレッドを見ると必要なことは書いてあります。

備忘録として対応方法をこのあとの項目に記載します。

問題点

OUTPUT(出力)でOmniSharpLogに「Did not find 'Microsoft.NETCore.App' in lock file.」というエラーが出ている。
スクリーンショット 2020-05-22 17.41.21.png

monoのmsbuildが16.3以上出ないと発生する。
Homebrewでmonoをインストールした場合にmonoは6.8.0.123(2020/5/22現在)がインストールされるが、msbuildは16.1系のためにdotnet3.x系で問題が発生する。

$ msbuild -version
Microsoft (R) Build Engine version 16.1.85+gad9c9926a7 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

16.1.85.40109

対応方法

Homebewでインストールしたmonoをアンインストールする。

$ brew uninstall mono

Download - Stable | Mono」から6.8.0 Stableをダウンロードしてセットアップする。
msbuildが16.3以上確認する。

$ msbuild -version
Mono 向け Microsoft (R) Build Engine バージョン 16.5.0-ci
Copyright (C) Microsoft Corporation.All rights reserved.

16.5.0.16201

Code→Preferences(基本設定)→Settings(設定)を選択する。
Search Settings(設定の検索)に「useGlobalMono」を入力して絞り込む。
Omnisharo:Use Global Monoを「never」に変更する
vscodesetting.png

「Restart OmniSharp」する。
PROBLEMS(問題)からCS0246やCS0518などのエラーが消えているか確認する。

エラー詳細

Visual Studio Codeで問題タブで、項目を選んで右クリック→コピーで取得した情報。

CS0246_CS0518.png

{
    "resource": "/Users/xxxxx/develpoment/test/obj/Debug/netcoreapp3.1/test.AssemblyInfo.cs",
    "owner": "csharp",
    "code": "CS0246",
    "severity": 8,
    "message": "The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [test]",
    "source": "csharp",
    "startLineNumber": 14,
    "startColumn": 12,
    "endLineNumber": 14,
    "endColumn": 18
}

{
    "resource": "/Users/xxxxx/develpoment/test/obj/Debug/netcoreapp3.1/test.AssemblyInfo.cs",
    "owner": "csharp",
    "code": "CS0518",
    "severity": 8,
    "message": "Predefined type 'System.String' is not defined or imported [test]",
    "source": "csharp",
    "startLineNumber": 14,
    "startColumn": 55,
    "endLineNumber": 14,
    "endColumn": 61
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1