简体   繁体   English

发布Web项目 - MSBuild不复制依赖项目的DLL,这些DLL未添加对Web项目的引用

[英]Publish web project - MSBuild does not copy dependent projects' DLL which are not added reference to web project

My web application basically have three seperated projects: 我的Web应用程序基本上有三个独立的项目:

  1. A web project "MyWeb" which I want to publish to production environment 我想要发布到生产环境的Web项目“MyWeb”
  2. A Library project "MyBusiness" which define the Business layer's interfaces. 一个库项目“MyBusiness”,它定义了业务层的接口。 This project is referenced by MyWeb project 该项目由MyWeb项目引用
  3. Another Library project "MyBusinessImplementation" which contain the Business layer's implementation (concrete classes implement the Business layer's interfaces). 另一个库项目“MyBusinessImplementation”,它包含Business层的实现(具体类实现了Business层的接口)。

To do Dependency Injection, my MyWeb project just add reference to the MyBusiness interfaces project, not the implementation (or else my web project is closely tied to the implementation, and also I can't prevent my developers from making a "new" object of a concrete class in my web project). 要做依赖注入,我的MyWeb项目只是添加对MyBusiness接口项目的引用,而不是实现(或者我的web项目与实现密切相关,而且我也无法阻止我的开发人员创建一个“新”对象我的web项目中的具体类)。

Without adding reference directly to the Business implementation project, when building the project, Visual Studio doesn't know to copy the implementation project's DLL into the web's bin folder, so I added this into MyWeb project file: 在不直接向Business实现项目添加引用的情况下,构建项目时,Visual Studio不知道将实现项目的DLL复制到web的bin文件夹中,因此我将其添加到MyWeb项目文件中:

<PropertyGroup>
    <BuildDependsOn>BuildDependentProjects;$(BuildDependsOn);</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
    <ProjectToBuild Include="$(SolutionDir)\MyBusinessImplementation\MyBusinessImplementation.csproj">
    <Properties>Configuration=$(Configuration)</Properties>      
    </ProjectToBuild>    
</ItemGroup>
<Target Name="AfterBuild">
    <Copy SourceFiles="$(SolutionDir)\MyBusinessImplementation\bin\$(Configuration)\MyBusinessImplementation.dll" DestinationFolder="$(SolutionDir)\MyWebSite\bin"></Copy>    
</Target>
<Target Name="BuildDependentProjects">    
    <MSBuild Projects="@(ProjectToBuild)" />    
</Target>

The problem is, when I publish MyWeb project from Visual Studio 2012, or when I run 当我从Visual Studio 2012发布MyWeb项目或运行时,问题是

"MSBuild "MyWeb.jsproj" \\T:Package \\P:Configuration=Debug" “MSBuild”MyWeb.jsproj“\\ T:Package \\ P:Configuration = Debug”

I see that the MyBusinessImplementation.dll is copied into MyWeb's bin folder of my working code directory but NOT in the published package directory. 我看到MyBusinessImplementation.dll被复制到我工作代码目录的MyWeb的bin文件夹中,但不会复制到已发布的包目录中。

I've also tried to change the DestinationFolder of the Copy task to an absolute path like "C:\\abc" then I see the .dll file is copied successfully to the abc folder, but still not copied to my Package's web's bin folder. 我还尝试将Copy任务的DestinationFolder更改为绝对路径,如“C:\\ abc”,然后我看到.dll文件已成功复制到abc文件夹,但仍未复制到我的Package的web的bin文件夹中。

It looks like you are missing a step of adding the copied item to the WebDeploy manifest and package before its deployed. 看起来您错过了在部署之前将复制的项目添加到WebDeploy清单和包中的步骤。

Check this post out for a great answer on how to include extra files to the package. 查看这篇文章,了解如何在软件包中包含额外文件的绝佳答案。
How do you include additional files using VS2010 web deployment packages? 如何使用VS2010 Web部署包包含其他文件?

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

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