无NuGet/Visual Studio的IIS服务器上NuGet包操作及程序集报错解决
解决IIS服务器上Microsoft.CodeDom.Providers.DotNetCompilerPlatform程序集加载失败问题
不用安装Visual Studio,用以下两种方法就能解决:
方法一:用独立NuGet CLI安装
- 下载独立的
nuget.exe(直接搜索获取即可),放到服务器任意目录或复制到网站根目录 - 打开服务器CMD,导航到网站根目录,执行命令:
nuget install Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 1.0.5.0 - 找到生成的
packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5.0\lib\net45目录,把里面的Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll复制到网站的bin文件夹
方法二:从开发机复制已有的程序集
- 在开发机的项目
packages文件夹里找到对应1.0.5.0版本的程序集文件 - 直接复制该
dll文件到服务器网站的bin目录 - 检查网站根目录的
web.config,确保程序集版本配置正确:<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/> </compilers> </system.codedom> - 若web.config有绑定重定向,确认版本匹配:
<dependentAssembly> <assemblyIdentity name="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" publicKeyToken="31bf3856ad364e35" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-1.0.5.0" newVersion="1.0.5.0"/> </dependentAssembly>
最后确保IIS应用池账户拥有网站bin目录的读取权限。
内容的提问来源于stack exchange,提问作者user153923
相关产品推荐
相关产品推荐

