我有一个解决方案(ASP.NET、.NET 4.0)似乎没有正确更新其 dll。我注意到,当我在进行更改后对其进行编译时,它看不到我所做的添加。
我最近将解决方案的目标平台切换到 x86,因为我们现在将它部署到 x64 服务器上,而我现在在 x64 Win7 机器上维护它。 (我不知道这是否与它有关,见下文。)在我隔离问题之后,当我测试时,我发现如果我在其中一个 aspx 文件上选择“在浏览器中查看”,它突然看到了我之前所做的更改。我梳理了主项目的 bin 文件夹中的目录,我注意到 dll 被保存到两个不同的位置:bin 文件夹的根目录和 bin/x86/debug/。第一个位置在我简单编译解决方案时得到更新,第二个位置在我对其中一个 aspx 文件使用“在浏览器中查看”时得到更新。
有谁知道可能导致此行为的错误设置?
更新:@Vinkal 提供的答案让我相信 Debug 正在查看编译代码的 bin/
文件夹而不是 bin/x86/debug/
,代码被编译到哪里。这可能是核心问题吗?
最佳答案
I combed through the directories in the main project's bin folder, and I noticed dlls were being saved to two different places: the root of the bin folder, and bin/x86/debug/. The first location was getting updated when I simply compiled the solution, and the second was getting updated when I used "view in browser" on one of the aspx files.
检查 Configutation Manager
至于什么platform
被选中,如下面的屏幕截图 #1 所示。
屏幕截图 #1:配置管理器
如果您创建新的 platform
(此处 x86
),Output Path
自动设置为 bin\x86\Debug\
.请参见下面的屏幕截图。
屏幕截图 #2: 选择项目属性时build设置
所以当你编译项目时,二进制文件将根据Output Path
被复制(在我的例子中,bin\x86\Debug\
代表在 Platform x86
中设置的 Platform Target
)。如下图所示确认,编译时会复制所有二进制文件。正如您所提到的,当您编译解决方案时,bin 文件夹的根目录 正在更新。所以你的项目Output Path
对于 Platform (Any CPU, x86 or x64)
必须设置为 Bin 文件夹的根目录你设置了Platform Target
注意:如果Post-Build event commmand
设置为copy Binaries,也会复制到Path
在 Post-Build event command
中指定.
在浏览器中查看:使用 View in browser
打开页面时,将再次编译页面并根据 Output Path
复制二进制文件在 Project Properties
中指定如屏幕截图 #2 所示。正如你提到的bin\x86\Debug\
当您在浏览器中查看页面时更新,它表示 Output Path
设置为 bin\x86\Debug\
在你的Project Properties
, 在下面显示的屏幕截图中,当使用 View in Browser
打开页面时, 二进制将变为 Bin
文件夹和平台选择为 Any CPU
构建后事件命令:如果您还设置了 Post-build event command
,如下图所示,要复制不同位置的路径,在这两种情况下(即当你编译和 View in Browser
时),它都会被复制到 Path
中。在 Post-build event command
中指定
编辑:
如前所述here , 使用 <probing>
元素:
您可以使用应用程序配置文件 中的元素来指定运行时在查找assembly
时应搜索的子目录。 .以下示例显示了如何指定运行时应搜索的目录。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin2\subbin;bin3"/>
</assemblyBinding>
</runtime>
</configuration>
privatePath
属性包含运行时应搜索的目录 assemblies
.如果应用程序位于 C:\Program Files\MyApp,运行时将查找 assemblies
未在 C:\Program Files\MyApp\Bin、C:\Program Files\MyApp\Bin2\Subbin 和 C:\Program Files\MyApp\Bin3 中指定代码库。 privatePath中指定的目录必须是应用程序基目录的子目录
所以在你的情况下,修改 web.config
如下图
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;bin\x86\debug"/>
</assemblyBinding>
</runtime>
</configuration>
关于c# - VS2010 DLL 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28705978/