简体   繁体   中英

My .NET Framework WPF App doesn't see my .NET Standard Library

I am trying to follow up with a tutorial and I did everything perfectly, I checked 3 times. I am new to this.

This is the class, this was a .NET Core library and I migrated it by simply editing the .csproj file:

namespace WiredBrainCoffee.Simulator
{
    public class CoffeeMachine
    {
        public int CounterCappuccino { get; private set; }

        public void MakeCappuccino()
        {
            CounterCappuccino++;
        }
    }
}

And this is the .NET Framework WPF application code which contains a simple button and a text box that updates and adds one every time I press the button.

        public MainWindow()
        {
            InitializeComponent();
            _coffeMachine = new CoffeMachine();
            txtCappucinoCounter.Text = _coffeMachine.CounterCappuccino.ToString();
        }

        private void ButtonMakeCappuccinoClick(object sender, RoutedEventArgs e)
        {
            _coffeMachine.MakeCappuccino();
            txtCappucinoCounter.Text = _coffeeMachine.CounterCappuccino.ToString();
        }

The problem is it is not working. _coffeMachine has a red underline every where and I can't generate the using WiredBrainCoffee.Simulator automatically so I tried manually but it is not working either.

Right click on your project, Add -> Reference, select the other Project.

Ensure the class you want to use is public (its internal by default).

You also need to define the type of _coffeMaker. In your case it needs to be a class-variable

It should work then

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM