Referenced assemblies are not copied over

Topics: Bugs
Oct 19, 2007 at 4:58 PM
When I am trying to build my DocProject I am getting the following error:

Error Missing source assembly or file in output directory: C:\AIM\WorkflowServer\Manuals\bin\Debug\WorkflowServer.Foundation.dll

It looks like the build process does not copy the referenced assembly to the proper location. If I copy the file there manually, it builds just fine. Another issue which may or may not be related to this one is that every time I run build command on the doc project, the assembly referenced in in the docproject is rebuilt regardless of whether there were any changes in the source code of referenced assembly.

Any idea what I am doing wrong?

Below is the content of the output window:

------ Build started: Project: Foundation, Configuration: Debug Any CPU ------
Build started 10/19/2007 10:48:46 AM.
Target _CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
Target CopyFilesToOutputDirectory:
Foundation -> C:\AIM\WorkflowServer\foundation\bin\Debug\WorkflowServer.Foundation.dll
Copying file from "WorkflowServer.Foundation.xml" to "bin\Debug\WorkflowServer.Foundation.xml".
Target PostBuildEvent:
"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\..\..\SDK\v2.0\Bin\gacutil.exe" /i C:\AIM\WorkflowServer\foundation\bin\Debug\WorkflowServer.Foundation.dll /f
Microsoft (R) .NET Global Assembly Cache Utility. Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.

Assembly successfully added to the cache

Build succeeded.

Time Elapsed 00:00:00.32
------ Build started: Project: Manuals, Configuration: Debug Any CPU ------
Build started 10/19/2007 10:48:48 AM.
Target ResolveProjectReferences:
Target GetCopyToOutputDirectoryItems:
Target CopyFilesToOutputDirectory:
Manuals -> C:\AIM\WorkflowServer\Manuals\bin\Debug\Manuals.dll

Starting help build for Manuals...
Preparing target directory...

System.InvalidOperationException was thrown during build preparation:

Missing source assembly or file in output directory: C:\AIM\WorkflowServer\Manuals\bin\Debug\WorkflowServer.Foundation.dll

Total Time Elapsed: 00:00:00.0781260

No steps executed.

Manuals help build failed.


Build FAILED.

Time Elapsed 00:00:01.12
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========
Coordinator
Oct 19, 2007 at 6:41 PM
Hi,

Strange error you got there ;)

First, I'd like to address the second issue that you mentioned. DocProject does not build the source projects - MSBuild does. So if you're building your DocProject in Visual Studio and you're using project references to define the source assemblies, then Visual Studio/MSBuild are going to determine when the source project needs to be rebuilt (this occurs even before DocProject gets control of the build process). If you find this to be a problem then you may want to add your project's assembly as an External Source, which may inadvertently fix the first problem that you're experiencing; although, I recommend keeping a project reference instead if you can.

As for the error, DocProject does not copy the referenced projects to its bin folder, MSBuild does; however, it's strange that the file path in the error is pointing to your DocProject instead of the source project. In other words, the path should probably be, C:\AIM\WorkflowServer\foundation\bin\Debug\WorkflowServer.Foundation.dll. (That is, foundation instead of Manual.)

The output directory that the error refers to is the output directory of the source project. DocProject acquires this information from MSBuild. I don't see how you could have possibly added the DocProject as a source project to itself, so I have to assume that you've either modified paths or VS/MSBuild is, for some unknown reason, giving DocProject an invalid path.

Have you changed any MSBuild properties in the WorkflowServer.Foundation project file, such as <OutputPath>? Have you modified the DocProject's project file in any way?

If you want to see the output paths of your project as DocProject sees them then you can try adding the following code to the BuildStarting method of your Build Process Component (e.g., BuildProcess.cs or BuildProcess.vb):

context.TraceLine("Project reference paths:");
 
foreach (ISourceProject source in context.Engine.Project.Sources)
  context.TraceLine(source.Output.OutputPath);
You can cancel (Ctrl+Break) the build process when the first step begins. Look at the build output window in Visual Studio and see what paths have been written.

In my tests the output paths written do not point to the DocProject or DocSite, but instead point to the bin\Debug folder of the source projects themselves.

What version of Visual Studio are you using?

- Dave
Oct 19, 2007 at 9:13 PM
Thank you for a prompt response. No I did not change any properties of the Foundation project nor did I modify the project file. After reading your response I removed the reference to the Foundation project from the doc project, closed Visual Studio, reopened it and re-added the Foundation project. to the doc project. And guess what - now it seems to work fine. So whatever was wrong we will never know.

- Mike
Oct 19, 2007 at 9:28 PM
Nope. I was wrong. It does not work. I cleaned the bin folder in the manuals project and now I am getting this problem again. I will keep digging
Oct 19, 2007 at 10:20 PM
I do not get it. From what I can see in the project files I do not see what can confuse this thing. Below I included a (trimmed) copy of my project file. There is a project reference to the foundation prokject at the bottom of the file. Can you see what's wrong with it?

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EA0F00B1-957E-4428-A21D-0E12A936A28D}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Manuals</RootNamespace>
<AssemblyName>Manuals</AssemblyName>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(DocProjectBuildPath)\DaveSexton.DocProject.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties DoNotAskIncludeOutputInProject="True" SandcastleUseFriendlyHtmlFileNames="True" DefaultApplyToAll="False" DeploymentSandcastleDeploymentContent="Chm" SandcastleProduceHelp2x="False" SandcastleProduceHelp1x="True" BuildEngineProviderName="Sandcastle/Deployment" Sandcastle_PresentationName="Visual Studio 2005" IsDocProject="true" ProcessComponentTypeName="Manuals.BuildProcess" />
</VisualStudio>
</ProjectExtensions>
<ItemGroup>
<Reference Include="DaveSexton.DocProject, Version=1.8.0.0, Culture=neutral, PublicKeyToken=af1a4bab65cc4ece, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="BuildProcess.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Help\Comments\project.xml" />
.................................

<Content Include="Help\Styles\Presentation.css" />
</ItemGroup>
<ItemGroup>
<None Include="Help\Presentation\Shared\configuration\xamlSyntax.config" />
<None Include="Help\Presentation\Shared\copyHavana.bat" />
<None Include="Help\Presentation\Shared\HxsTemplate\template.HxF" />
<None Include="Help\Presentation\Shared\HxsTemplate\template_A.HxK" />
<None Include="Help\Presentation\Shared\HxsTemplate\template_B.HxK" />
<None Include="Help\Presentation\Shared\HxsTemplate\template_F.HxK" />
<None Include="Help\Presentation\Shared\HxsTemplate\template_K.HxK" />
<None Include="Help\Presentation\Shared\HxsTemplate\template_N.HxK" />
<None Include="Help\Presentation\Shared\HxsTemplate\template_S.HxK" />
<None Include="Help\Presentation\Shared\SharedDocModel.ps1" />
<None Include="Help\Presentation\Style\Configuration\MRefBuilder.config" />
<None Include="Help\Presentation\Style\Configuration\sandcastle.help1x.config" />
<None Include="Help\Presentation\Style\Configuration\sandcastle.help2x.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{B4F97281-0DBD-4835-9ED8-7DFB966E87FF}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Foundation\Foundation.csproj">
<Project>{BA84DA62-6A19-4FAB-AB4D-309D78E51C05}</Project>
<Name>Foundation</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Help\Art\" />
</ItemGroup>
</Project>
Coordinator
Oct 19, 2007 at 11:02 PM
Hi Mike,

A workaround might be to ensure that the project reference has Copy Local set to True so that MSBuild automatically copies the project's output to your DocProject's output folder. (Although, that is usually the default anyway so I wonder if it's already set). To set this property, find the project reference to the Foundation library under your DocProject's References folder in Solution Explorer and open the properties window.

Would you mind running a test to see what VS returns for the source project's path?

Add the following code in the BuildStarting method of your Build Process Component file:

context.TraceLine("Source projects: ");
 
foreach (ISourceProject source in context.Engine.Project.Sources)
{
  context.TraceLine("{0} ({1}):", source.Name, source.GetType().Name);
  context.TraceLine("\tProject directory: {0}", ((IAnyProject) source).Directory);
  context.TraceLine("\tRelative output path: {0}", source.Output.RelativeOutputPath);
}
Cancel the build after the first step starts and please post the output of the code above here, thanks. It should be something like the following:

Foundation (VSSourceProject):
  Project directory: C:\AIM\WorkflowServer\foundation\
  Relative output path: bin\Debug\
Although, I expect the project directory to incorrectly point to the Manuals project instead of the Foundation project.

- Dave
Coordinator
Oct 19, 2007 at 11:07 PM
Hi Mike,

I've just seen your post with the project file contents and I realize that you can fix the problem by setting Copy Local to True, as I stated previously (this setting corresponds to the <Private> element in your project reference, which either should not be present at all or should contain the value: True).

I just tried building a DocProject with Copy Local set to False on a project reference and got the same error as you! I'm investigating...

- Dave
Coordinator
Oct 19, 2007 at 11:15 PM
Hi Mike,

It's a bug in BuildEngine.cs that I've fixed for the next release. Setting CopyLocal to True should work for now though.

- Dave
Coordinator
Oct 19, 2007 at 11:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 25, 2007 at 5:48 PM
Hi, Dave,
I followed your recommendation and changed the CopyLocal to true and now this thing seems to work. There is still a glitch. It seems that when you add a reference to an up to date project and then build the doc project the refrenced dll is not copied and I am getting the same error. If you rebuild the project though, the dll is copied over and from this moment on everything goes smoothly. It seems that for up to date projects, the CopyFilesToOutputDirectory step is skipped even though the dll is not there yet.
As to another issue I originally rported - it turned out to be a figment of my imagination.
Anyway, now the doc project seems to work and I am really impressed by the speed and quality of your response,
Coordinator
Oct 25, 2007 at 11:16 PM
Hi,

The glitch that you see is still caused by the same bug that has been fixed for the next release. Basically, DocProject was never supposed to reference the assembly that is copied over from MSBuild. It has always referenced the assemblies from their source locations and this bug was a regression issue, probably in 1.8.0.

Thanks for reporting the problem.

- Dave