如何获得ASP.NET MVC发布了一个本机二进制复制到bin目录 [英] How to get ASP.NET MVC Publish to copy over a native binary to the bin dir

查看:443
本文介绍了如何获得ASP.NET MVC发布了一个本机二进制复制到bin目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2013年VS一库组件我靠包装本地的dll创建ASP.NET MVC 4的网站。我是原生的DLL复制到该项目的生成后事件项目的输出目录。这使我能够运行在IIS防爆preSS的网站,工作正常。然而,当我去发布站点本地DLL被留在灰尘。理想的情况是我想无论是在Win32或x64​​原生DLL取决于什么平台,在Visual Studio中当前选定出版。任何人都知道如何让本机DLL由发布命令挖出了?

I have created an ASP.NET MVC 4 website in VS 2013. One of the library assemblies I depend on wraps a native dll. I copy that native DLL to the project's output dir in the project's post-build event. That allows me to run the website under IIS Express and that works fine. However, when I go to Publish the site the native DLL gets left in the dirt. Ideally I want either the Win32 or x64 native dll published depending on what platform is currently selected in Visual Studio. Anybody know how to get native DLLs to be scooped up by the Publish command?

顺便说一下我试过的伎俩,你添加链接的DLL到项目,并设置生成操作为None,将复制到输出目录为始终复制。虽然这样的作品,它仅适用于本地的dll的一个特定位数。小于理想

BTW I've tried the trick where you "add link" the DLL to the project and set the Build Action to None and set the "Copy to Output Directory" to Copy Always. While that works, it only works for one particular bitness of the native dll. That is less than ideal.

推荐答案

您可以添加条件的 .csproj的(或 .vbproj )通过手动编辑它的文件。

You can add conditions to the .csproj (or .vbproj) file by editing it by hand.


  1. 保存项目中的任何工作。

  2. 右键单击Solution Explorer中的项目节点,然后单击卸载项目

  3. 整个项目将压缩为一个节点。右键单击该节点,选择编辑<项目名称>的.csproj (或 .vbproj

  1. Save any work in the project.
  2. Right-click the project node in solution explorer, and click Unload Project.
  3. The whole project will collapse into a single node. Right click that node and select Edit <Project Name>.csproj (or .vbproj).

向下滚动,查看您的DLL,您使用。它看起来应该是这样的:

Scroll down and look for your DLL that you used for. It should look something like:

<ItemGroup>
    <Content Include="bin\Release\x86\My.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

复制,并添加一个条件。在这种情况下,您要根据平台去改变它。下面是做到这一点的方法之一。请注意,您应该分析该项目文件,以确定添加特定配置的最佳状态。你也应该将目录更改为匹配您的32位和64位的DLL文件的(相对)的位置。

Duplicate it and add a condition. In this case, you want to change it based on platform. Here is one way to do that. Do note that you should analyze the project file to determine the best condition to add for your particular configuration. You should also change the directory to match the (relative) location of your 32 and 64 bit DLL files.

<ItemGroup Condition=" '$(PlatformTarget)' == 'x86' ">
    <Content Include="bin\$(Configuration)\x86\My.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>
<ItemGroup Condition=" '$(PlatformTarget)' == 'x64' ">
    <Content Include="bin\$(Configuration)\x64\My.dll">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

Visual Studio中无法正确显示此(它会显示一个破碎的DLL链接和一个有效的DLL链接),但请放心这种方法的功能。它还有助于了解Visual Studio项目文件只是一个MSBuild配置文件等等。因此,尽管Visual Studio不支持的方式来添加或显示条件或其他一些的MSBuild选项,它们都将正确如果根据MSBuild的文档配置的功能。

Visual Studio doesn't display this correctly (it will show a broken DLL link and a valid DLL link), but rest assured this method functions. It also helps to understand that a Visual Studio project file is nothing more than an MSBuild configuration file. So, although Visual Studio doesn't support a way to add or display conditions or some other MSBuild options, they all will function correctly if configured according to the MSBuild documentation.

这篇关于如何获得ASP.NET MVC发布了一个本机二进制复制到bin目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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