缺少程序集,但是当我添加它时,它说无法找到元数据文件C#.nET

时间:2016-09-28 16:48:36

标签: c# .net wpf winforms

我之前已经创建了一些类似的问题,但这个问题没有任何意义。

如果我不添加引用,则说

The type or namespace name 'Window' could not be found (are you missing a using directive or an assembly reference?)

当我添加

PresentationFramework.dll

它说

Metadata file 'PresentationFramework.dll' could not be found

我做了一些研究,似乎The type or namespace name 'Window' 需要PresentationFramework.dll

当我尝试在我的应用程序内部编译时(不是从VS)

,为什么我的应用程序会抛出这个错误

源代码

using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Windows;


namespace SimpleBuilder
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// store code
    /// select what features
    /// print out textfile with all the code from the features
    /// compile that textfileContent to a exe
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void fakeMessageOne()
        {
            if(fakeMessageCheckbox.IsChecked == true)
            {
                fakeMessage1 fkmsg = new fakeMessage1();
                fkmsg.fakeMessage();
            }
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {



            CSharpCodeProvider csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", frameworkTextbox.Text } });
            CompilerParameters parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, outputTextbox.Text, true);
            parameters.GenerateExecutable = true;
            parameters.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
            parameters.ReferencedAssemblies.Add("System.dll");
            //parameters.ReferencedAssemblies.Add("PresentationFramework.dll"); commented this out for now since it wasnt working

            CompilerResults result = csc.CompileAssemblyFromSource(parameters, sourceTextbox.Text);
            if (result.Errors.HasErrors)
            {
                result.Errors.Cast<CompilerError>().ToList().ForEach(error => errorTextbox.Text += error.ErrorText + "\r\n");
            }
            else
            {
                errorTextbox.Text = "--- Build Succeeded! ---";
            }

        }
    }
}

代码我试图从我的应用程序内部编译

using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Windows;


namespace SimpleBuilder
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// store code
    /// select what features
    /// print out textfile with all the code from the features
    /// compile that textfileContent to a exe
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void fakeMessageOne()
        {
            Messagebox.Show("Hello World");
        }
    }
}

0 个答案:

没有答案