2014-06-17 22 views
9

Yalnızca desteklenenRuntime ayarlarını içeren app.config dosyasını exe dosyasına gömmem gerekir. Yerleşik bir kaynak oluşturma eylemi yapmayı denedim, ancak şimdi yapılandırma dosyasındaki değerleri okumaya çalışmıyor ve çalışmıyor. supportedRuntime öğesini exe dosyasına gömme

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v2.0.50727"/> 
     <supportedRuntime version="v4.0"/> 
    </startup> 
</configuration> 

böylece fikri de .NET 4.0 benim .Net 2.0 exe ​​çalıştırmaktır: Bu benim yapılandırma dosyasıdır. herhangi bir fikir?

Teşekkürler.

+0

.net geriye dönük uyumluluk taşır . Bir makinede 4.0 yüklü ise, 2.0 ile derlenmiş bir uygulamayı çalıştıracaktır. İki etikete ihtiyacınız yok. –

+7

Teşekkürler Andrew, ama maalesef bu doğru değil. – Shahab78

+0

İşte başlıyoruz; Bunu deneyin: http://stackoverflow.com/a/13915723/436282 –

cevap

1

Bu mümkün değil. Eğer kesinlikle config dosyası olmadan çalıştırılabilir olması gerekiyorsa, size en yakın CLR'yi çalıştıracak yönetilmeyen bir yükleyici yazabilirsiniz.

sen olduğunu varsayalım C# uygulaması gibi:

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

Sen yönetilmeyen () yükleyici oluşturabilir gibi:

#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; 
} 

diğer bilgiler: https://www.codeproject.com/Articles/607352/Injecting-Net-Assemblies-Into-Unmanaged-Processes