[英]Add a reference in C# Rider to PresentationFramework
Well, I tried to implement this function好吧,我试着实现这个功能
```
static void DisplayMessage()
{
string userMessage = string.Format("1000 in hex is {0:x}", 1000);
System.Windows.MessageBox.Show(userMessage);
}
```
But to compile and use this function i need to add a reference to PresentationFramework.但是要编译和使用这个函数,我需要添加对 PresentationFramework 的引用。 I use Rider, i don't know how to add a reference correctly, because i see this when i want to add a reference.
我使用 Rider,我不知道如何正确添加引用,因为当我想添加引用时会看到这个。
Then, I tried to add reference on this file然后,我尝试在此文件上添加参考
```
C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\5.0.10\PresentationFramework.dll
```
And now it builds my code but also catches unhandled exeception.现在它构建了我的代码,但也捕获了未处理的异常。
```
using System;
namespace LearningSharp
{
class Program
{
static void Main(string[] args)
{
DisplayMessage();
}
static void DisplayMessage()
{
string userMessage = string.Format("1000 in hex is {0:x}", 1000);
System.Windows.MessageBox.Show(userMessage);
}
}
}
```
Unhandled exception. System.IO.FileLoadException: Could not load file or assembl
y 'WindowsBase, Version=5.0.10.0, Culture=neutral, PublicKeyToken=31bf3856ad364e
35'. The located assembly's manifest definition does not match the assembly refe
rence. (0x80131040)
File name: 'WindowsBase, Version=5.0.10.0, Culture=neutral, PublicKeyToken=31bf3
856ad364e35'
at System.Windows.MessageBox.ShowCore(IntPtr owner, String messageBoxText, St
ring caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult de
faultResult, MessageBoxOptions options)
at System.Windows.MessageBox.Show(String messageBoxText)
at LearningSharp.Program.DisplayMessage() in C:\Users\dchal\RiderProjects\Lea
rningSharp\LearningSharp\Program.cs:line 16
at LearningSharp.Program.Main(String[] args) in C:\Users\dchal\RiderProjects\
LearningSharp\LearningSharp\Program.cs:line 9
Process finished with exit code -532,462,766.
So how make this code work?那么如何使这段代码工作呢? How to add a reference in Rider?
如何在 Rider 中添加引用? Can I do it simplier than boring finding dll in my files?
我可以比在我的文件中查找 dll 更简单吗? I've created a solution like this (You may say that i need to use another template, but i want to learn how to add references and make code work properly)
我已经创建了这样的解决方案(您可能会说我需要使用另一个模板,但我想学习如何添加引用并使代码正常工作)
And this is my csproj (i've deleted a references which i tried to add above)这是我的 csproj(我删除了我试图在上面添加的引用)
有点晚了,但我也偶然发现了这个问题,我就像@Adam KaczMarski 说的那样解决了它,右键单击项目-> 管理 NuGet 包,键入PresentationFramework
并添加它,我可以使用System.Windows.Shapes
命名空间没有任何进一步的问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.