Question

I have a MSBuild script that realizes some operations before compiles a solution that have many projects.
I need to include a file (SharedAssemblyInfo_$(ambiente).cs) created during the process in every project Properties folder.

Any clues to resolve this?

Thanks in advance!

PS.: Here is my script:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"/>

  <ItemGroup>
    <Solution Include="Stoque.ECM.sln" />

    <Compile Include="..\SharedAssemblyInfo_$(ambiente).cs">
        <Link>Properties\SharedAssemblyInfo_$(ambiente).cs</Link>
    </Compile>

  </ItemGroup>
  <PropertyGroup>
    <TMaior>2</TMaior>
    <TMedio>0</TMedio>
    <TMenor>0</TMenor>

    <DeployDir>E:\compartilhada\abaris</DeployDir>
  </PropertyGroup>

  <Target Name="GetProjects">
    <GetSolutionProjects Solution="%(Solution.Fullpath)">
      <Output ItemName="ProjectFiles" TaskParameter="Output" />
    </GetSolutionProjects>
  </Target>

  <Target Name="AssemblyVersion">
    <Time Format="yyMMdd">
      <Output TaskParameter="FormattedTime" PropertyName="TRevisao" />
    </Time>
    <AssemblyInfo CodeLanguage="CS" OutputFile="..\SharedAssemblyInfo_$(ambiente).cs" AssemblyVersion="$(TMaior).$(TMenor).*" AssemblyFileVersion="$(versao)" AssemblyInformationalVersion="$(versao)" />   
    <!-- <Copy SourceFiles="..\SharedAssemblyInfo_$(ambiente).cs" DestinationFolder="%(ProjectFiles.Filename)\Properties" ContinueOnError="false" /> -->
  </Target>

  <Target Name="Compile" DependsOnTargets="GetProjects">
    <MSBuild Projects="%(ProjectFiles.Fullpath)"
    Properties="WebProjectOutputDir=$(DeployDir)\$(ambiente)\$(versao)\SITES_PUBLICADOS\%(ProjectFiles.Filename);Platform=$(Platform);Configuration=$(Configuration);OutputPath=$(DeployDir)\$(ambiente)\$(versao)\%(ProjectFiles.Filename)">
    </MSBuild>
  </Target>

</Project>
Was it helpful?

Solution

I see you have an <ItemGroup> -> <Compile> item in your root MSBuild .proj. That's a good first step, but you need to stick that in the actual .csproj, not just your build script.

To do this, add a BeforeBuild task to each .csproj that adds in the file you want as a link.

Something like:

<Target Name="BeforeBuild">
  <_FilesToInclude Include="..\SharedAssemblyInfo_$(ambiente).cs" />
    <Compile Include="@(_FilesToInclude->'%(Filename)%(Extension)')">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Compile>
  </ItemGroup>
</Target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top