How to tell dependent projects that the output should be copied locally when using ProjectReference?

I have two projects, name them Project A and Project B.

Project A has a CopyToOutputDirectory content element, as shown below:

<ItemGroup>
    <Content Include="MyExampleDependency.txt">
        <Link>MyFunOutputLocation\MyExampleDependency.txt</Link>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
</ItemGroup>

References Project B Project A:

<ItemGroup>
    <ProjectReference Include="..\..\Shared\Project A.csproj">
        <Project>{My GUID here</Project>
        <Name>Project A</Name>
    </ProjectReference>
</ItemGroup>

When I create Project B, it is smart enough to copy the DLL created by Project A, as well as this text file, to the output. That is, I get something like this when I create Project B:

  • bin\Project A\Project A.dll
  • bin\Project A\MyFunOutputLocation\MyExampleDependency.txt
  • bin\Project B\Project A.dll
  • bin\Project B\Project B.exe
  • bin\Project B\MyFunOutputLocation\MyExampleDependency.txt

I have a new dependency that I want to start generating in Project A; for example, from the T4 transform. This can be a file that I generated using a task <Exec, or a file created using some custom target or similar. For instance:

<ItemGroup>
    <Content Include="Foo.tt">
        <Generator>TextTemplatingFileGenerator</Generator>
        <OutputFilePath>$(OutDir)</OutputFilePath>
        <LastGenOutput>Foo.xml</LastGenOutput>
    </Content>
</ItemGroup>

Now, when I create, I get something like this:

  • bin\Project A\Project A.dll
  • bin\Project A\Foo.xml < - Project B!
  • bin\Project A\MyFunOutputLocation\MyExampleDependency.txt
  • bin\Project B\Project A.dll
  • bin\Project B\Project B.exe
  • bin\Project B\MyFunOutputLocation\MyExampleDependency.txt

, , Project A.dll, DLL, Project B. Project B, Project A ( B .csproj )?

+4
1

Foo.tt, , Foo.txt " ", , - 'll itemgoup, CopyToOutputDirectory.

, ( ) Project A Content . , , _CopyFilesMarkedCopyLocal, . PreBuildEvent A BeforeBuild, B, , BeforeBuild .

A.csproj

<Target Name="BeforeBuild">
    <ItemGroup>
        <Content Include="$(OutputPath)\Bar.txt" Condition="Exists('$(OutputPath)\Bar.txt')">
            <Link>Bar.txt</Link>
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>
</Target>

Edit

.

Project A Foo / T4.

<Target Name="Foo">
    <ItemGroup>
        <Content Include="Foo.xml">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>
</Target>

, , - TextTemplating, Transform .

<PropertyGroup>
    <TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\TextTemplating\Microsoft.TextTemplating.targets" />

, .. AfterTransform, .targets.

<PropertyGroup>
    <AfterTransform>$(AfterTransform);Foo</AfterTransform>
</PropertyGroup>

90% , 9% Project B Visual Studio Project A. Rebuild AfterTransform, Import, , BeforeBuild , , Visual Studio . InitialTargets Project A.

<Project InitialTargets="Foo"

1% - .xml , .pdb, VS , .dll .

+3

All Articles