简体   繁体   中英

MSbuild and multiple projects with same class library references

I have a solution file with a class library and a couple of windows services. 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.

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.

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? It works fine with web projects and the same temp directory.

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.

The solution in my project, was to use a different output directory for each service.

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