C# 部署 ASP.NET“网站”后缺少 using 指令或程序集引用问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12091141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
missing a using directive or an assembly reference issue after deploying an ASP.NET "Website"
提问by Dev Dreamer
So I have an ASP.NET website, which works great on my machine. But when I deployed it on web host server, its giving me an error saying:
所以我有一个 ASP.NET 网站,它在我的机器上运行良好。但是当我将它部署在网络主机服务器上时,它给了我一个错误说:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 15: using Microsoft.VisualBasic;
Line 16: using System.Data.SqlClient;
Line 17: using Newtonsoft.Json;
Line 18: using System.Globalization;
Line 19: using System.Text.RegularExpressions;
I think this is a classic error, and there are similar questions already being asked, even by me before. But, all the solutions are either not clear or not applicable.
我认为这是一个经典的错误,并且已经有人问过类似的问题,即使是我之前。但是,所有的解决方案要么不明确,要么不适用。
Since its a "website" project, so the property of the aspx.cs file does not contain any field such as "Build Action" or "Copy Local" etc. I am using Newtonsoft to parse JSON. Can someone please suggest me STEP-BY-STEP way to get rid of this problem?
由于它是一个“网站”项目,所以 aspx.cs 文件的属性不包含任何字段,例如“构建操作”或“复制本地”等。我使用 Newtonsoft 来解析 JSON。有人可以建议我逐步解决这个问题吗?
I came across solutions such as clean-up and such. Clean what? In my solution explorer, there's this BIN folder which contains the dll, xml, and pdb for the Newtonsoft library; which is AS-IT-IS copied on to the webhost server, using COPY WEBSITE tool.
我遇到了诸如清理之类的解决方案。清洁什么?在我的解决方案资源管理器中,有一个 BIN 文件夹,其中包含 Newtonsoft 库的 dll、xml 和 pdb;使用 COPY WEBSITE 工具将 AS-IT-IS 复制到网络主机服务器上。
What do I need to do to fix the problem? Thanks a bunch.
我需要做什么来解决问题?谢谢一堆。
回答by Anant Dabhi
Take these steps: -> Solution explorer window -> right mouse on your .cs file in Visual Studio -> select Properties -> Build action = Compile
采取以下步骤: -> 解决方案资源管理器窗口 -> 在 Visual Studio 中的 .cs 文件上用鼠标右键 -> 选择属性 -> 构建操作 = 编译
or
或者
Remove reference of your Newtonsoft and copy Newtonsoft.dll to your bin folder and give a reference from there.
删除对 Newtonsoft 的引用并将 Newtonsoft.dll 复制到 bin 文件夹并从那里提供引用。
回答by Amnesh Goel
Build your website and publish it to some folder. Then copy all requisite files to your web server. Just check whether you got Newtonsoft dll in bin folder (web server) or not. If you do not have, then copy it from local machine and paste it to web server.
构建您的网站并将其发布到某个文件夹。然后将所有必需的文件复制到您的 Web 服务器。只需检查您是否在 bin 文件夹(Web 服务器)中安装了 Newtonsoft dll。如果没有,请从本地计算机复制它并将其粘贴到 Web 服务器。
回答by sisve
This would happen if you're not deploying to an application root, but a normal windows folder.
如果您不是部署到应用程序根目录,而是部署到普通的 Windows 文件夹,就会发生这种情况。
The bin folder must be in your application root (~/bin) for assemblies to be resolved correctly. You may change this by changing your private probing path in your web.config-file, but that's a bad solution for this.
bin 文件夹必须位于应用程序根目录 ( ~/bin) 中,才能正确解析程序集。您可以通过更改 web.config 文件中的私有探测路径来更改此设置,但这是一个糟糕的解决方案。
Ensure you're uploading your application to an folder configured to host an application. This can be done in your IIS Manager if you have Remote Desktop access. Shared hosting solutions may provide this functionality in a web-based configuration tool. Log into your "control panel" and look around.
确保您将应用程序上传到配置为托管应用程序的文件夹。如果您具有远程桌面访问权限,则可以在 IIS 管理器中完成此操作。共享主机解决方案可以在基于 Web 的配置工具中提供此功能。登录到您的“控制面板”并环顾四周。
Or you could just contact your hosting support.
或者您可以联系您的托管支持。

