我有一个解决方案。第一个项目包含 Entity Framework 模型,输出类型是控制台应用程序。其他项目是前端,asp.net mvc 5 应用程序,具有第一个项目中实体的 CRUD View 。第一个项目从第二个项目引用,我还在 web.config 中添加了依赖程序集:
<dependentAssembly>
<assemblyIdentity name="VolLoader" publicKeyToken="null" />
</dependentAssembly>
但是当我访问使用此程序集中的实体的 View 时,我收到 View 编译错误:
Compiler Error Message: CS0246: The type or namespace name 'VolLoader' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 29:
Line 30:
Line 31: public class _Page_Views_JobMon_Index_cshtml : System.Web.Mvc.WebViewPage<IEnumerable<VolLoader.Data.JobToWatch>> {
Line 32:
Line 33: #line hidden
在views文件夹中的web.config中添加namespace()会导致每个 View 出现编译错误。
程序集被复制到输出。
但是当我将第一个项目的输出类型更改为类库时,它可以工作,没有编译错误。我不明白为什么?有人有想法吗?
最佳答案
我想我找到了为什么会发生这种情况。我不是100%确定,但我无法重新编译system.web.dll来证明这一点。 我在system.web.dll中找到了这段代码:
namespace System.Web.Compilation
{
/// <summary>Provides a container for building an assembly from one or more virtual paths within an ASP.NET project.</summary>
public class AssemblyBuilder
......
}
第 381 行:
internal CompilerParameters GetCompilerParameters()
{
CompilerParameters compilerParameters = this._compilerType.CompilerParameters;
string text = this._tempFiles.TempDir;
if (this.CultureName != null)
{
text = Path.Combine(text, this.CultureName);
Directory.CreateDirectory(text);
compilerParameters.OutputAssembly = Path.Combine(text, this.OutputAssemblyName + ".resources.dll");
}
else
{
compilerParameters.OutputAssembly = Path.Combine(text, this.OutputAssemblyName + ".dll");
}
如您所见,它只需要 dll:
compilerParameters.OutputAssembly = Path.Combine(text, this.OutputAssemblyName + ".dll");
关于c# - 当引用构建为控制台应用程序的程序集时,MVC View get 编译错误 (CS0246)。当它构建为类库时 - 它工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21616799/