2014-06-17 2 views
9

supportedRuntime 설정 만 포함 된 app.config 파일을 내 exe 파일에 포함해야합니다. 빌드 작업 내장 리소스를 시도했지만 config 파일에서 값을 읽지 않고 작동하지 않습니다. supportedRuntime을 exe 파일에 포함

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

그렇게 생각뿐만 아니라 닷넷 4.0 내 닷넷 2.0 EXE 파일을 실행하는 것입니다 : 이것은 내 설정 파일입니다. 어떤 아이디어?

감사합니다.

+0

.NET은 이전 버전과 호환 . 컴퓨터에 4.0이 설치되어 있으면 2.0으로 컴파일 된 응용 프로그램이 실행됩니다. 두 개의 태그가 필요하지 않습니다. –

+7

앤드류 감사합니다.하지만 불행히도 사실이 아닙니다. – Shahab78

+0

여기에 우리가 간다. 이것을 시도하십시오 : http://stackoverflow.com/a/13915723/436282 –

답변

1

이것은 불가능합니다. 구성 파일없이 실행 파일을 반드시 사용해야하는 경우 가장 가까운 CLR을 실행하는 관리되지 않는 로더를 작성하면됩니다.

당신이 가진 가정의 C# 응용 프로그램과 같은 :

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

당신은 관리되지 않는 () 로더를 만들 수 있습니다와 같은 :

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

상세 정보 : https://www.codeproject.com/Articles/607352/Injecting-Net-Assemblies-Into-Unmanaged-Processes

관련 문제