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.
The following steps are working for me:
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: Microsoft.Web.Administration.dll
: <HintPath>C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
. You could adapt this path to eg <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.
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
<HintPath>$(windir)\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
.To resolve, they either install IIS via Programs in Control Panel or via command line as @DzmitryLahoda pointed out.
Again, any trick pointing you to the NuGet packages is improper,
Search for it in NuGet and install it. It will get installed in packages folder, change the location according to your project structure and re-add the references to reflect new path. Generally I create a lib folder and place all the external libraries.
Folder structure of the project can be
lib -> external libraries
src - > code
tools -> tools such as nant, etc
Microsoft.Web.Administration
is used to manage IIS programmatically and it is not available from add reference window. By adding reference from C:\Windows\System32\inetsrv would create reference issues. So, better to have it in lib folder internal to the project and check it in SVN.
C:\Windows\System32\inetsrv
or
C:\Windows\winsxs\x86_microsoft.web.administration-nonmsil_31bf3856ad364e35_6.1.7600.16385_none_c8472944f22a9c81
C:\Windows\WinSxS\x86_microsoft.web.administration-nonmsil_31bf3856ad364e35_6.3.9600.16384_none_5d1097a8ac709c4e
Try to ensure these assemblies are installed via prebuild event:
Dism /online /Enable-Feature /FeatureName:IIS-WebServerManagementTools /All
In installed whole IIS with all features this way, so used FeatureName
is guesstimate for assemblies. Try next to list all features for alternative:
dism /online /Get-Features
DISM
is available for Windows earlier then 8: To service inbox drivers in an offline image of Windows Vista with Service Pack 2 (SP2) or Windows Server 2008 with SP2, you must use the Windows 7 version of DISM or PkgMgr. The Windows 7 version of DISM is available in Windows 7 and Windows PE 3.0 operating systems, or can be installed with the Windows Automated Installation Kit (Windows AIK) or the Windows OEM Preinstallation Kit (Windows OPK) for Windows 7.
To service inbox drivers in an offline image of Windows Vista with Service Pack 2 (SP2) or Windows Server 2008 with SP2, you must use the Windows 7 version of DISM or PkgMgr. The Windows 7 version of DISM is available in Windows 7 and Windows PE 3.0 operating systems, or can be installed with the Windows Automated Installation Kit (Windows AIK) or the Windows OEM Preinstallation Kit (Windows OPK) for Windows 7.
Also can try for Windows 7 and below: start /w pkgmgr /iu:IIS-WebServerManagementTools
A bit of extra info, not a direct answer. IIS and IIS Express use two different versions of the same DLL, so your app might accidentally get the wrong one. See http://rdingwall.com/2013/09/22/microsoft-web-administration-confusion/
You could always just load the dll dynamically, and never directly reference it in your project. That way you avoid all of the "reference" issues, NuGet packages, and so on. However, you will still need to verify that the dll is available on the end target.
var windowsPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
var DLL = Assembly.LoadFile($@"{windowsPath}\System32\inetsrv\Microsoft.Web.Administration.dll");
if (DLL != null)
{
// Get Server...
foreach (Type type in DLL.GetExportedTypes())
{
if (type.Name == "ServerManager")
{
dynamic server = Activator.CreateInstance(type);
dynamic applicationPools = server.ApplicationPools;
foreach (dynamic pool in applicationPools)
{
MessageBox.Show(pool.Name);
}
// Done -- Get Out...
break;
}
}
}
The simplest way to do this is install NuGet in Visual Studio from this link. http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c
Then, in Visual Studio, go to Tools->NuGet Package Manager-> Package Manager Console
Then, select Default Project to be the project that you want to install to.
Finally, Run Install-Package Microsoft.Web.Administration command.
Add new project to your solution called "referenced assemblies" and add the DLL to this project - this way the DLL will be in the source control. You can then reference the project using the "Browse" option in add reference.
Your colleagues will be happy because you they will not miss this DLL as it is in source control.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.