0

I have been using the How do I install .NET Framework only when it's not already installed? solution succesfully BUT when I tried to run another new app(.exe from debug) that needs the same .NET framework version that it has been installed by the previous application's installer, the system gives me the ERROR: "Unable to find the version of the runtime to run this application".

This means to me that the new app cannot use the installed .NET framework and needs to install it's "own" .NET

Eitherways I will have to make a setup for my new app so it can install the .NET when the target machine does not have it. But this time I would like to do it in a way that the framework can be used by future applications. How can I do this?

Community
  • 1
  • 1
poloapolo
  • 97
  • 2
  • 12
  • The info in your link is for .Net 4.0. Do you need v4.0 or 3.0/3.5 is enough? – i486 Apr 16 '15 at 07:30
  • .NET 4 is what i need for now – poloapolo Apr 16 '15 at 07:32
  • Have you tried this: `try ExpandConstant('{dotnet40}'); Result := True; except ... end` – i486 Apr 16 '15 at 07:33
  • No I didn't. Where should I put this line? – poloapolo Apr 16 '15 at 07:36
  • I will add example as answer because it will not be readable as comment. It is for .Net 2.0 but you can modify it. I suspect that your app is 32-bit and you run it on 64-bit OS. In that case you may read incorrect registers and get missing values each time. – i486 Apr 16 '15 at 08:40
  • That answer is badly outdated. Microsoft does not want you to do this anymore. You need to find out why you [don't get this](http://stackoverflow.com/a/10033128/17034). Something wrong with the way you build your app, I guess. – Hans Passant Apr 16 '15 at 08:44
  • I noticed that when I clean the .Net installations and I try to run the application, I get a different Error with code 0xc0000135 Does this mean something? @HansPassant I build it in the Visual Studio 2012 and until now I didn't knew this could go wrong – poloapolo Apr 16 '15 at 10:01

1 Answers1

0

Here is sample .Net install. It assumes that local .Net setup may exist in the same directory.

[Code]
function InitializeSetup: Boolean;
var
    ErrorCode: Integer;
    Result1 : Boolean;
begin
   try
     ExpandConstant('{dotnet20}');
     Result := True;
   except
     begin
       Result1 := MsgBox('NOTE: Some modules of this software require Microsoft .NET Framework. Would you like to install the .NET Framework now?', mbConfirmation, MB_YESNO) = idYes;
       if Result1 = false then
       begin
         Result:=True;
       end
       else
       begin
         if not ShellExec('open', ExpandConstant('{src}\dotnetfx.exe'),'', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
         begin
           if not ShellExec('open', ExpandConstant('{src}\dotnetfx3.exe'),'', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
           begin
             if not ShellExec('open', ExpandConstant('{src}\dotnetfx3setup.exe'),'', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
             begin
               ShellExec('open', 'http://www.microsoft.com/en-us/download/details.aspx?id=17851','', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode)
             end
           end
         end;
         Result:=False;
       end;
     end;
   end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
i486
  • 6,491
  • 4
  • 24
  • 41
  • Version 4, not "whatever I hope is there" – Hans Passant Apr 16 '15 at 08:45
  • Read my comments above. My sample is for Net 2.0 and can be modified. It is to show how to use `ExpandConstant` for .Net check. In case of .Net 2.0 requirement, any newer .Net setup is OK. For that reason it checks for 2.0, 3.0, etc. And (btw) the title says nothing about .Net version. – i486 Apr 16 '15 at 08:52
  • Because you answer "Yes" on question for .Net installation and it cannot be done. If you answer No, then setup will continue (without .Net). – i486 Apr 16 '15 at 11:34
  • That's not what is happening here. You exit the setup no matter what happens with the `ShellExec` calls, just when the user says yes to the message dialog. – TLama Apr 16 '15 at 12:24
  • If setup does not exit, then it will finish before .Net installation is complete (the installation is independent process). And you may try to run the installed .Net application without .Net framework. I agree it is not perfect but this is example for question "Where should I put this line" above. – i486 Apr 16 '15 at 12:36