How to reference Microsoft.Web.Administration?

后端 未结 11 1637
你的背包
你的背包 2020-12-08 09:25

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 al

相关标签:
11条回答
  • 2020-12-08 09:47

    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.

    0 讨论(0)
  • 2020-12-08 09:49
    1. If you project file, change the hint path to <HintPath>%windir%\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>.
    2. Check in. Then anyone who checks out should see the proper reference if IIS is installed. If IIS is not installed, there will be a reference error they need to resolve.

    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,

    https://blog.lextudio.com/2015/05/whats-microsoft-web-administration-and-the-horrible-facts-you-should-know/

    0 讨论(0)
  • 2020-12-08 09:50

    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
    
    0 讨论(0)
  • 2020-12-08 09:51

    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;
            }
        }
    }
    
    
    0 讨论(0)
  • 2020-12-08 09:52

    Use Nuget:

    Microsoft.Web.Administration

    0 讨论(0)
提交回复
热议问题