Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference Microsoft.Web.Administration?

Tags:

.net

iis

The Microsoft.Web.Administration assembly is found in C:\Windows\System32\inetsrv on my machine. I believe it is installed as part of IIS. The assembly is also in the GAC.

How should I reference this assembly from my project, given that I want to commit the project to SVN for others to checkout. Microsoft.Web.Administration does not appear in the Visual Studio 'Add References' list. I can add a reference to C:\Windows\System32\inetsrv\Microsoft.Web.Administration, but this seems like a bad idea as other developers might have it installed on a different path or drive.

Or I could copy it into the project folder, but then I have to commit the binary to SVN.

like image 587
Weyland Yutani Avatar asked Aug 07 '13 13:08

Weyland Yutani


People also ask

What is Microsoft Web administration?

The Microsoft. Web. Administration namespace contains classes that a developer can use to administer IIS Manager. With the classes in this namespace, an administrator can read and write configuration information to ApplicationHost. config, Web.


2 Answers

The following steps are working for me:

  1. Go to C:\Windows\System32\inetsrv and check if the file Microsoft.Web.Administration.dll exists. If you are missing the Microsoft.Web.Administration.dll in C:\Windows\System32\inetsrv, enable IIS Management Console in your Windows Features:

Adding the management service to windows features

  1. In your Visual Studio project, add the reference to the Microsoft.Web.Administration.dll: enter image description here
  2. Now your .proj-file has the following the entry: <HintPath>C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>. You could adapt this path to e.g. <HintPath>%windir%\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath> to make it more robust.

When you move the app to a different system, the app also references to the Microsoft.Web.Administration.dll on the target system. Because the Microsoft.Web.Administration.dll could be different between the windows systems it is not recommended to deliver a copy of this assembly file by the app. A copy could be incompatible with the IIS on the target system.

It is also not recommended to reference a copy of the assembly on the same system, because perhaps the Microsoft.Web.Administrator.dll and the IIS will change due an Windows Update! Then your referenced copy of Microsoft.Web.Administrator.dll is incompatible with the updated IIS.

When the Microsoft.Web.Administrator.dll is missing on the target system, then activate the Management Console as descibed in step 1 above. Alternatively you can use the cmd (open as Administrator) and activate the Windows Feature Management Console by DISM.exe via the following command:

C:\Windows\System32\Dism.exe /enable-feature /online /featurename:IIS-ManagementConsole 

This command could be useful when you want to distribute your app via an setup.

like image 91
Simon Avatar answered Sep 24 '22 00:09

Simon


You may modify your project file manually. Adding/Changing the reference like below will find the assembly in GAC regardless of its location:

<Reference Include="Microsoft.Web.Administration, Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">     <SpecificVersion>False</SpecificVersion> </Reference> 

Of course, if the feature "IIS management console" is installed only. You may simply leave a hint in code:

#warning Windows feature "IIS management console" must be installed locally 
like image 31
deve loper Avatar answered Sep 25 '22 00:09

deve loper