简体   繁体   中英

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:

  1. A web project "MyWeb" which I want to publish to production environment
  2. A Library project "MyBusiness" which define the Business layer's interfaces. This project is referenced by MyWeb project
  3. Another Library project "MyBusinessImplementation" which contain the Business layer's implementation (concrete classes implement the Business layer's interfaces).

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).

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:

<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

"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.

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.

It looks like you are missing a step of adding the copied item to the WebDeploy manifest and package before its deployed.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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