简体   繁体   English

MSbuild和具有相同类库引用的多个项目

[英]MSbuild and multiple projects with same class library references

I have a solution file with a class library and a couple of windows services. 我有一个带有类库和几个Windows服务的解决方案文件。 All the services have a project reference to the class library. 所有服务都具有对类库的项目引用。

In my build file I'm building each service in release mode, zipping the files and copying the zip files to a webserver where our production servers can download the zip files from. 在我的构建文件中,我正在发布模式下构建每个服务,将文件压缩并将zip文件复制到Web服务器,我们的生产服务器可以从该Web服务器下载zip文件。

The problem is that only the first services is built and deployed. 问题在于只有第一个服务才能构建和部署。 All others fail with a CSC : error CS0006: Metadata file "classlibrary.dll" could not be found. 所有其他文件均因CSC失败:错误CS0006:找不到元数据文件“ classlibrary.dll”。

I've made a test solution that reproduces the problem. 我已经制作了一个重现该问题的测试解决方案。 One empty class library, and two empty console applications, both with references to the class library. 一个空的类库和两个空的控制台应用程序,均引用该类库。

Is it because the temp directory is the same? 是否因为temp目录相同? It works fine with web projects and the same temp directory. 它适用于Web项目和相同的temp目录。

And then this build file. 然后这个构建文件。

    <?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\Tools\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
  </PropertyGroup>
  <Import Project="Tools\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <PropertyGroup>
    <ExtensionTasksPath>$(MSBuildProjectDirectory)\Tools\MSBuild.ExtensionPack\</ExtensionTasksPath>
  </PropertyGroup>
  <Import Project="Tools\MSBuild.ExtensionPack\MSBuild.ExtensionPack.tasks" />

  <PropertyGroup>
    <ProjectName>MSbuild test</ProjectName>
  </PropertyGroup>


  <Target Name="DeployAll" >
    <Message Text="DeploymentPackage $(ProjectName)" />

    <PropertyGroup>
      <TempDeploymentDirectory>$(MSBuildProjectDirectory)\DeploymentPackage\</TempDeploymentDirectory>      

      <ProjectFile1>ConsoleApplication1\ConsoleApplication1.csproj</ProjectFile1>
      <ProjectFile2>ConsoleApplication2\ConsoleApplication2.csproj</ProjectFile2>

    </PropertyGroup>

    <RemoveDir Directories="$(TempDeploymentDirectory)" />

    <MSBuild Projects="$(ProjectFile1)" Properties="Configuration=Release;OutDir=$(TempDeploymentDirectory)" Targets="Clean;Build"/>

    <!-- Zipping copying files removed for readability -->

    <RemoveDir Directories="$(TempDeploymentDirectory)" />    

    <MSBuild Projects="$(ProjectFile2)" Properties="Configuration=Release;OutDir=$(TempDeploymentDirectory)" Targets="Clean;Build"/>


  </Target>





</Project>

Building the classLibrary before each application worked for the demo project, but not for the real project. 在每个应用程序都为演示项目工作之前构建classLibrary,而不是为实际项目工作。

The solution in my project, was to use a different output directory for each service. 我项目中的解决方案是为每个服务使用不同的输出目录。

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

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