Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MSBuild put *.XmlSerializers.dll assembly in the root folder of published web application?

I have a build process which takes my VS 2008 .NET 2.0 ASP.NET project and builds it using MSBuild. The project contains ASPX files, plus a web service, and also connects to another web service ;)

All seems to work well except MSBuild puts the *.XmlSerializers.dll assembly file into the folder _PublishedWebsites\MySite rather than in _PublishedWebsites\MySite\bin like it does with the other dll.

Does it matter that the *.XmlSerializers.dll assembly file is not in the bin folder?

Or should I use my build process to copy the *.XmlSerializers.dll assembly into the bin folder after MSBuild has finished?

like image 525
Matthew Lock Avatar asked Jan 21 '10 02:01

Matthew Lock


2 Answers

You don't need this assembly unless you will be serializing and deserializing types from your assembly. This assembly is generated by the compiler to save your application from having to generate it once it is up and running.

If you intend on doing serialization, keep the assembly as it will help with performance. If you don't intend on doing any serialization then feel free to ignore it or remove it altogether.

For more information about this practice please see XML Serializer Generator Tool:

The XML Serializer Generator creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.

like image 121
Andrew Hare Avatar answered Sep 28 '22 04:09

Andrew Hare


Yes, it does matter that the XmlSerializers assembly is not in the bin directory. Using the Fusion Log Viewer I confirmed my suspicion that the DLL was not being loaded when it was left in the web application root.

To correct this, you can add an AfterBuild target that moves the file to the correct location. I use the following snippet, but newer versions of MsBuild have a Move task:

  <Target Name="AfterBuild">
    <!-- Don't do this when the final destination is the same as build destination (local builds) -->
    <Exec Command="move /Y &quot;$(WebProjectOutputDir)\$(AssemblyName).XmlSerializers.dll&quot; &quot;$(WebProjectOutputDir)\bin&quot;" Condition="'$(OutDir)' != '$(OutputPath)'"/>
  </Target>

Note: If you are building and running the web app from the same directory (as is usually the case when running locally on your dev machine) and have the project setting "Generate serialization assembly" set to On, the file is generated in the bin directory. This is why I configured the task not to be executed in that case.

I could have simply made sure the file existed, but I wanted to make sure the build failed if for some reason the file was not in the expected place during integration builds.

like image 27
Mario Avatar answered Sep 28 '22 04:09

Mario