I am using msbuild.exe to automate my build from the command line.
I do the following steps.
here are my targets
first one to compile
<Target Name="BuildProjects"  DependsOnTargets="BeforeBuild">
    <ItemGroup>      
  <BuildProjectFiles Include="**\MyCompany.Project1\MyCompany.Project1.csproj" />
  <BuildProjectFiles Include="**\MyCompany.Project2\MyCompany.Project2.csproj" />
  <BuildProjectFiles Include="**\MyCompany.Project2\MyCompany.Project2-CE.csproj" />
      ... and some more
    </ItemGroup>
    <MSBuild Projects="@(BuildProjectFiles)" Properties="AllowUnsafeBlocks=true;Configuration=$(Configuration);OutputPath=$(MSBuildProjectDirectory)\Deploy\bin\%(BuildProjectFiles.FileName)">
        <Output TaskParameter="TargetOutputs"
                ItemName="BuildProjectsOutputFiles" />
    </MSBuild>
</Target>
and now the target to zip every compiled project to its one file.
<Target Name="ZipProjects" DependsOnTargets="BuildProjects">
    <CreateItem
        Include="@(BuildProjectOutputFiles)"
            AdditionalMetadata="AssemblyName=%(Filename);ProjectName=%(RelativeDir)">
        <Output TaskParameter="Include" ItemName="BuildProjectsOutputFiles123"/>
    </CreateItem>
    <CreateItem Include="%(BuildProjectsOutputFiles123.RelativeDir)*" AdditionalMetadata="OutputFileName=$(MSBuildProjectDirectory)\Deploy\dist\$(Configuration)\%(BuildProjectsOutputFiles123.AssemblyName)-$(MajorNumber).$(MinorNumber).$(ReleaseNumber).zip;WorkingDirectory=%(BuildProjectsOutputFiles123.RelativeDir)">
        <Output TaskParameter="Include" ItemName="BuildProjectsOutputFiles456"/>
    </CreateItem>
    <Zip Files="@(BuildProjectsOutputFiles456)"
        WorkingDirectory="%(BuildProjectsOutputFiles456.WorkingDirectory)" 
        ZipFileName="%(BuildProjectOutputFiles456.OutputFileName)"  />
        <!-- ZipLevel="9"/> -->
</Target>
So what happens is that every project I specified in BuildProjectFiles gets compiled into the folder <rootdir>\deploy\bin\<name of the csproj file without extension\
In the second step I use the MSBuild.Community.Tasks Zip-Task to zip every project and copy it to <rootdir>\deploy\dist\release\<assemblyname>-<version>.zip
So basically the assembly project1.exe and its dependencies are in the file project1-2.4.7.zip after executing msbuild.
That works very well. But now I have a change that I can't figure out how solve. I have two assemblys with the same assembly name (one for Windows and the other for Windows CE) so the first project compiles and creates a folder project2-2.4.7.zip and then the next project compiles and overwrites the zip file.
Now I want the Zip-File to be named after the .csproj file (like the bin folder).
Since my one project file is called mycompany.project2.csproj and the other one mycompany.project2-ce.csproj I should be fine.
In short: How can I pass the project name to the zip target?
Is this suitable? $(MSBuildProjectName)
MSBuild Reserved Properties
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With