视觉工作室锁定DLL,因为使用“嵌入资源”嵌入视图 [英] Visual studio locking DLL because of embedding views using "embedded resource"

查看:154
本文介绍了视觉工作室锁定DLL,因为使用“嵌入资源”嵌入视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目A包含一个视图,我们称之为View1.ascx在属性窗口



中标记为嵌入式资源,PROJECT A和PROJECT B和C都加载view1从PROJECTA.DLL使用自定义资源提供程序



这样我可以重复使用我的跨项目视图。



可悲的是,这导致视觉工作室在PROJECTA.dll每次更改后首次无法构建PROJECT B或C。

 错误12无法将C:\GIT\PROJECTA\PROJECTA\bin\PROJECTA.dll复制到bin \PROJECTA.dll,超过重试次数为10.失败。 

有没有办法让这项工作?或者我应该以某种方式将所有重复使用的观点移动到单独的装配体?这些视图使用PROJECT A中的类,所以我将它们保留在PROJECT A中。为了使所有内容都清楚:通过第二次构建通常的工作,代码和视图都在工作,这是一个非常大的浪费时间,等待10秒钟,第一次构建尝试失败。

解决方案

Apparantly我的assemblyresourceprovider使用AssemblyResourceVirtualFile:从Assembly.LoadFile加载我的dll的VirtualFile oebject,而不是使用推荐的方法在内存中加载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(资源名称);
return resourceStream;
}
返回null;
}


PROJECT A contains a View , let's call it View1.ascx marked as "Embedded Resource" in the properties window

both PROJECT A and PROJECT B and C load that view1 from the PROJECTA.DLL using a custom resource provider

This way I can reuse my views across projects.

Sadly, this causes visual studio to be unable to build PROJECT B , OR C the first time around, after each change to the PROJECTA.dll

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

Is there any way to make this work? or should I somehow move all "re-used" views to a seperate assembly? The views use classes from PROJECT A so that's why I kept them inside PROJECT A

To make everything clear: Building it a second time around usually works, and the code and views are all working, it's just a really big waste of time to have to wait 10 seconds for the first build attempt to fail.

解决方案

Apparantly my assemblyresourceprovider used a AssemblyResourceVirtualFile:VirtualFile oebject that was loading my dll from Assembly.LoadFile instead of using the recommended way of loading dlls in memory as described here: http://fzysqr.com/2010/04/26/asp-net-mvc2-plugin-architecture-tutorial/ I left the old line of code in comment for you guys to see where the problem was

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;
}

这篇关于视觉工作室锁定DLL,因为使用“嵌入资源”嵌入视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆