2016-09-28 20 views
0

所以我最近問了一個問題,爲什麼我的引用沒有被添加,那是因爲我忘了添加一段代碼。 這段代碼是這樣的。爲什麼我的應用程序讓我無法發現元數據文件,即使我剛添加它?

parameters.ReferencedAssemblies.Add("Microsoft.CSharp"); 

我補充說,剪斷,現在它拋出我這個錯誤,而不是。

Metadata file 'Microsoft.CSharp' could not be found 

之前從來沒有看到任何元數據錯誤,所以這是拋棄我。

我的源代碼

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"); 

      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! ---"; 
      } 

     } 
    } 
} 

這是我嘗試在我的應用程序編譯(不是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() 
     { 
      Messagebox.Show("Hello World"); 
     } 
    } 
} 

我的舊後Why is my application say that im missing references even though I have them?

回答

1

ReferencedAssemblies.Add()正在尋找文件名,所以添加擴展名:

parameters.ReferencedAssemblies.Add("Microsoft.CSharp.dll"); 
+0

哦這些小錯誤「.dll」 謝謝你的工作! –

+0

CodeDom的名稱是什麼?因爲我無法在裝配中找到它。 –

+0

它會是System.dll嗎? –

相關問題