To nie jest możliwe. Jeśli absolutnie musisz mieć plik wykonywalny bez pliku konfiguracyjnego, najbliżej możesz go napisać niezarządzanego programu ładującego, który uruchomi CLR dla ciebie.
Załóżmy, że masz C# app jak:
using System;
namespace DumpVersion
{
class Program
{
static int EntryPoint(string argument)
{
Console.Out.WriteLine(argument);
Console.Out.WriteLine(Environment.Version);
Console.In.ReadLine();
return 0;
}
static void Main()
{
EntryPoint("Main");
}
}
}
Można tworzyć niezarządzalny (c++) Ładowarka jak:
#include <metahost.h>
#pragma comment(lib, "mscoree.lib")
#import "mscorlib.tlb" raw_interfaces_only \
high_property_prefixes("_get","_put","_putref") \
rename("ReportEvent", "InteropServices_ReportEvent")
int wmain(int argc, wchar_t* argv[])
{
HRESULT hr;
ICLRMetaHost *pMetaHost = NULL;
ICLRRuntimeInfo *pRuntimeInfo = NULL;
ICLRRuntimeHost *pClrRuntimeHost = NULL;
// build runtime
// todo: add checks for invalid hr
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost));
hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_PPV_ARGS(&pRuntimeInfo));
if (hr != S_OK) {
hr = pMetaHost->GetRuntime(L"v2.0.50727", IID_PPV_ARGS(&pRuntimeInfo));
}
hr = pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost,
IID_PPV_ARGS(&pClrRuntimeHost));
// start runtime
hr = pClrRuntimeHost->Start();
// execute managed assembly
DWORD pReturnValue;
hr = pClrRuntimeHost->ExecuteInDefaultAppDomain(
L"c:\\temp\\TestLoading\\DumpVersion\\bin\\Debug\\DumpVersion.exe",
L"DumpVersion.Program",
L"EntryPoint",
L"hello .net runtime",
&pReturnValue);
// free resources
pMetaHost->Release();
pRuntimeInfo->Release();
pClrRuntimeHost->Release();
return 0;
}
Więcej informacji: https://www.codeproject.com/Articles/607352/Injecting-Net-Assemblies-Into-Unmanaged-Processes
.net jest wstecznie kompatybilny . Jeśli komputer ma zainstalowaną wersję 4.0, uruchomi aplikację skompilowaną z wersją 2.0. Nie potrzebujesz dwóch tagów. –
Dzięki Andrew, ale niestety to nie prawda. – Shahab78
Tutaj idziemy; spróbuj tego: http://stackoverflow.com/a/13915723/436282 –