Visual Studio Codeでdotnet 3.x系のプロジェクトを開くとエラーCS0246やCS0518が出る問題の対処
はじめに
プロジェクトのTargetFrameworkにnetcoreapp3.0やnetcoreapp3.1を指定した場合に、Visual Studio Codeでプロジェクトを読み込むとCS0246やCS0518が発生する問題への対処方法です。
omnisharp-vscodeの対応方法スレッド
下記のスレッドを見ると必要なことは書いてあります。
- Did not find 'Microsoft.NETCore.App' in lock file. · Issue #3314 · OmniSharp/omnisharp-vscode
- Omnisharp not working on Mac · Issue #3407 · OmniSharp/omnisharp-vscode
備忘録として対応方法をこのあとの項目に記載します。
問題点
OUTPUT(出力)でOmniSharpLogに「Did not find 'Microsoft.NETCore.App' in lock file.」というエラーが出ている。
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」に変更する
「Restart OmniSharp」する。
PROBLEMS(問題)からCS0246やCS0518などのエラーが消えているか確認する。
エラー詳細
Visual Studio Codeで問題タブで、項目を選んで右クリック→コピーで取得した情報。
{
"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
}
Author And Source
この問題について(Visual Studio Codeでdotnet 3.x系のプロジェクトを開くとエラーCS0246やCS0518が出る問題の対処), 我々は、より多くの情報をここで見つけました https://qiita.com/s_ryuuki/items/51e11ca6259814275139著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .