繁体   English   中英

Visual Studio因使用“嵌入式资源”嵌入视图而锁定DLL

[英]Visual studio locking DLL because of embedding views using “embedded resource”

PROJECT A包含一个View,我们称之为View1.ascx,在属性窗口中标记为“Embedded Resource”

PROJECT A和PROJECT B和C都使用自定义资源提供程序从PROJECTA.DLL加载view1

这样我可以在项目中重用我的视图。

可悲的是,这导致visual studio在每次更改PROJECTA.dll后第一次无法构建PROJECT B或OR C

"Error  12  Could not copy "C:\GIT\PROJECTA\PROJECTA\bin\PROJECTA.dll" to "bin\PROJECTA.dll". Exceeded retry count of 10. Failed."

有没有办法让这项工作? 或者我应该以某种方式将所有“重用”视图移动到单独的程序集中? 视图使用PROJECT A中的类,这就是我将它们保存在PROJECT A中的原因

为了使一切清楚:第二次构建它通常是有效的,并且代码和视图都在工作,只需要等待10秒钟才能使第一次构建尝试失败,这真是浪费时间。

显然我的assemblyresourceprovider使用了AssemblyResourceVirtualFile:VirtualFile oebject,它正在从Assembly.LoadFile加载我的dll而不是使用推荐的方式在内存中加载dll,如下所述: http//fzysqr.com/2010/04/26/asp-net -mvc2-plugin-architecture-tutorial /我留下了旧的代码行,让你们看看问题出在哪里

public override System.IO.Stream Open()
{
    string[] parts = path.Split('/');
    string assemblyName = parts[2];
    string resourceName = parts[3];


    assemblyName = Path.Combine(HttpRuntime.BinDirectory, assemblyName);
    byte[] assemblyBytes = File.ReadAllBytes(assemblyName);
    System.Reflection.Assembly assembly = Assembly.Load(assemblyBytes);
    /*System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(assemblyName);*/
    if (assembly != null)
    {
        Stream resourceStream = assembly.GetManifestResourceStream(resourceName);
        return resourceStream;
    }
    return null;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM