IIRC, the reason the link is compiled twice, is because it is declared as a reference project in both solutions. Thus, both will call the assembly object a reference. This is how I understand it.
Create a group of elements for a reference project
<ItemGroup> <ProjectReference Include="refProject\refProject.csproj"> <Targets>Build</Targets> </ProjectReference> </ItemGroup>
Add target to create link
<Target Name="ComputeProjectReference" Inputs="@(ProjectReference)" Outputs="%(ProjectReference.Identity)__Forced"> <MSBuild Projects="@(ProjectReference)" Targets="%(ProjectReference.Targets)"> <Output TaskParameter="TargetOutputs" ItemName="ResolvedProjectReferences"/> </MSBuild> </Target> <Target Name="AfterProjectReference" AfterTargets="ComputeProjectReference"> <CreateItem Include="@(ResolvedProjectReferences)"> <Output TaskParameter="Include" ItemName="CopyFiles" /> </CreateItem> <Copy SourceFiles="@(CopyFiles)" DestinationFolder="$(AssemblyName)\$(OutputPath)" SkipUnchangedFiles="false" /> <ItemGroup> <NewAssemblies Include="$(AssemblyName)\$(OutputPath)%(CopyFiles.FileName)%(CopyFiles.Extension)" /> </ItemGroup> </Target>
Unfortunately, the MSBuild task does not accept links as a parameter. I suggest creating itemGroups that represent each project. sort of
<ItemGroup> <CompileA Include="ConsProject\Program.cs" /> <CompileA Include="ConsProject\Properties\AssemblyInfo.cs" /> <CompileA Include="ConsProject\Properties\Settings.Designer.cs"> <AutoGen>True</AutoGen> <DesignTimeSharedInput>True</DesignTimeSharedInput> <DependentUpon>Settings.settings</DependentUpon> </CompileA> </ItemGroup> <ItemGroup> <CompileB Include="OtherProject\Program.cs" /> <CompileB Include="OtherProject\Properties\AssemblyInfo.cs" /> <CompileB Include="OtherProject\Properties\Settings.Designer.cs"> <AutoGen>True</AutoGen> <DesignTimeSharedInput>True</DesignTimeSharedInput> <DependentUpon>Settings.settings</DependentUpon> </CompileB> </ItemGroup>
And create a goal to build projects with lists compiled once
<Target Name="Build" DependsOnTargets="ComputeProjectReference" > <Csc Sources="@(CompileA)" References="@(NewAssemblies)" TargetType="exe" OutputAssembly="$(AssemblyName)\$(OutputPath)\$(AssemblyName).exe" /> <Csc Sources="@(CompileB)" References="@(NewAssemblies)" TargetType="exe" OutputAssembly="$(AssemblyName)\$(OutputPath)\$(AssemblyName).exe" /> </Target>
source share