尝试将System.Media命名空间添加到Visual Studio Code项目

时间:2018-10-10 09:30:49

标签: c# visual-studio-code .net-assembly

我目前正在从事一个小型游戏项目,目标是使用CSharp编写程序。

该项目是一个控制台应用程序,具有基于文本的菜单和开始屏幕,我目前的目标是在应用程序启动时添加音频播放。

我已经研究了使音乐播放所需的条件,但是我却没有程序集。

这是我的代码:

using System;
using System.Media;

namespace AntFightingSim
{
class Program
{
    public static string[] menuButtons = new string[] { " Fight!(Press Space) ", " Exit The Game!(Press Escape)" };
    public static bool appRunning = true;
    public static string path;
    public static int buttonCount = 0;
    static void Main(string[] args)
    {
        path = "C:/Users/Spyros/OneDrive - Södertörn university/Project Folder/Csharp Projects/RandomProjects/AntFightingSim/Resources/Dragon Ball FighterZ - OST - Loading Theme.wav";
        MenuMethod();
    }

    static void MenuMethod()
    {

        while (appRunning && buttonCount != 1)
        {
            SoundPlayer player = new SoundPlayer();
            player.SoundLocation = path;
            player.Load();
            player.PlayLooping();
            Console.WriteLine("ANT INVESTMENT SIMULATOR");

            Console.WriteLine("Press any key to start");
            Console.Write("\n");
            Console.Write("\n");
            Console.ReadKey(true);

            Console.Write(menuButtons[0]);
            Console.Write(menuButtons[1]);
            ConsoleKeyInfo info = Console.ReadKey(true);
            if (info.Key == ConsoleKey.Spacebar)
                StartGame();
            else if (info.Key == ConsoleKey.Escape)
            {

                buttonCount++;

            }

        }
        while (appRunning && buttonCount == 1)
        {
            Console.Write("\n");
            Console.Write("\n");
            Console.WriteLine("Are you sure about that?(Press Escape Again)");
            ConsoleKeyInfo info = Console.ReadKey(true);
            if (info.Key == ConsoleKey.Escape)
            {
                appRunning = false;
            }

        }

    }


    static void StartGame()
    {
        buttonCount = 1;
    }
}

static class Ant
{
    public static int strength;
    public static int dexterity;
    public static int agility;
    public static string name;
    public static bool gender;
}
}

我搜索了错误:

  

名称空间“系统”中不存在类型或名称空间名称“媒体”(您是否缺少程序集引用?)[C:\ Users \ Spyros \ OneDrive-   索德特恩大学\项目文件夹\ Csharp项目\ RandomProjects \ AntFightingSim \ AntFightingSim.csproj]

但是关于如何将所述程序集引用获取到Visual Studio Code中,我丝毫没有任何线索。到目前为止,Google只给了我2004-2015年Visual Studio的结果。

哪个带领我到这里。出于绝望,我第一次在StackOverflow中撰写并发布了一个问题。有没有一种方法可以添加所说的名称空间/不同的名称空间,还是在Visual Studio Code中是不可能的?上帝的速度。

编辑:

经过一番搜索,我发现System.Media名称空间及其程序集(PresentationCore.dll)在NuGet列表中不存在。

由于我缺乏适当的组装知识,可以帮助我实现目标,因此现在我需要询问System.Media的替代名称及其播放音频文件的能力。

2 个答案:

答案 0 :(得分:0)

您需要引用包含System.Media的程序集。可以在这里找到详细指南:https://stackoverflow.com/a/42399545/1621861

答案 1 :(得分:0)

如果您的环境是.NET核心,则希望在.NET Framework中构建应用程序。