Earlier this year I posted an article demonstrating how to use the SGEN.exe utility to generate a serialization assembly. The article identified how to create a custom MSBuild task by editing the project file (e.g., csproj). I've recently come to discover that the MSBuild task will fail when automating a build of the project through TFS Build. The error presents itself as follows:
SGEN(0,0): error : File or assembly name 'C:....\bin\CustomLibrary.dll', or one of its dependencies, was not found.
Ultimately, the root of the problem goes back to the SGEN MSBuild task's usage of the $(OutputPath) variable. Even in TFS Build this is pointing to same location that Visual Studio would point to. TFS, however, will override the output locations of the compiled applications, but this variable doesn't get updated. As stated in the MSDN documentation, "OutputPath has been deprecated and OutDir should be used instead whenever possible.". I was happy to discover that by simply replacing the $(OutputPath) with $(OutDir) in the MSBuild task was all I needed to do; the task will execute properly both from my development machine as well as the build server.
My updated task resembles the following:
<Target Name="GenSerializationAssembly" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutDir)$(_SGenDllName)"> <SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutDir)" References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)"> <Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" /> </SGen></Target><Target Name="AfterBuild" DependsOnTargets="GenSerializationAssembly" />
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010R. Aaron Zupancic
E-mail