私は現在、C#コードを独自のexeファイルにコンパイルすることについて学んでいます。 それは本当にどのように動作するのか魅力的です!私のアプリケーションは、私がそれらを持っているにもかかわらず、参照が見つからないと言っているのはなぜですか?
これまでのところ私はこのテキストをテキストボックスに入れてテキストをC#コードに変換するはずのこの小さなアプリケーションを持っていましたが、「ビルド」を押すたびに参照を追加するように指示しています。 。
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");
}
}
}
とし:ここで
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");
}
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;
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! ---";
}
}
}
}
が自分のアプリケーションの内部でコンパイルしようとしてくれ
The type or namespace name 'CSharp' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
The type or namespace name 'CodeDom' does not exist in the namespace 'System' (are you missing an assembly reference?)
The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
The type or namespace name 'Window' could not be found (are you missing a using directive or an assembly reference?)
コードイムを投げエラーです:ここでは
は、ソースコードであります何の価値があるのか here is a image of the small application
コンパイルしようとしているコードを教えてください。 – Rob
ああ申し訳ありません!今すぐ追加してください! –
Visual Studioを使用してこれを構築していますか? –