Can installutil be used to install a service writt

2019-08-18 17:50发布

问题:

Can the installutil be used to install a service written with a newer version of the .NET Framework?

For example can the version from .NET Framework 2.0 be used to install a service written in .NET 4?

I'm aware that technically the version from .NET 4 should technically be available on account of the fact the service will obviously require it.

Additional information The reason for asking this is that a tool which we use to install services appears to be hard-coded with a path to the .NET Version 2.0 framework installutil. However the service I wanted to install was built with the .NET 4.0 Framework

回答1:

A application written to use any particular version of .NET needs that version of .NET installed. As long as the required version of .NET is installed, the service exe can execute. If the service exe can execute, the INSTALLUTIL can install it (assuming all other dependent assemblies are accessible).



回答2:

It turned out that you do actually need a version at least as new as the version of the framework the assembly is written in.

Microsoft (R) .NET Framework Installation utility Version 2.0.50727.6387 Copyright (c) Microsoft Corporation. All rights reserved.

Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files (x86)\example\example.exe ' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.. Microsoft (R) .NET Framework Installation utility Version 2.0.50727.6387 Copyright (c) Microsoft Corporation. All rights reserved.