Код: Выделить всё
Could not load file or assembly System.Runtime or one of its dependencies
Код: Выделить всё
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe"; //new compiler
process.StartInfo.Arguments = @"/out:""TestScript.exe"" /reference:""Microsoft.Data.SqlClient.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Data.Common.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.ComponentModel.Primitives.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Runtime.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\mscorlib.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Console.dll"" ""TestScript.cs""";
process.Start();
process.WaitForExit();
string PathToCSFIle = @"TestScript.exe";
Process.Start(PathToCSFIle);
return 0;
Код: Выделить всё
using System;
using Microsoft.Data.SqlClient;
var ConnectionString = @"Data Source=MyDataSource;Database=MyDatabase;Integrated Security=True;Encrypt=True;Trust Server Certificate=True;MultipleActiveResultSets=true";
var SQLQuery = @"SELECT TOP(100) * FROM MyTable";
using (var connection = new SqlConnection(ConnectionString))
{
connection.Open();
using (var command = new SqlCommand(SQLQuery, connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var ColumnData = reader["MyColumn"].ToString()!;
Console.WriteLine(ColumnData);
}
}
}
connection.Close();
}
Код: Выделить всё
The type 'XXX' is defined in an assembly that is not referenced. You must add a reference to assembly 'abc123'
Код: Выделить всё
'T': type used in a using statement must be implicitly convertible to 'System.IDisposable'
Команда csc (в коде) для компиляции:
Код: Выделить всё
@"/out:""TestScript.exe"" /reference:""Microsoft.Data.SqlClient.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Data.Common.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.ComponentModel.Primitives.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Runtime.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\mscorlib.dll"" /reference:""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Console.dll"" ""TestScript.cs""";
Код: Выделить всё
csc /out:"TestScript.exe" /reference:"Microsoft.Data.SqlClient.dll" /reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Data.Common.dll" /reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.ComponentModel.Primitives.dll" /reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Runtime.dll" /reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\mscorlib.dll" /reference:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.11\ref\net8.0\System.Console.dll" "TestScript.cs"
Подробнее здесь: https://stackoverflow.com/questions/792 ... d-not-load
Мобильная версия