MSbuild 4.0 fail to compile .Net 3.5 project

773 Views Asked by At

I am using Msbuild 4.0.

In our project few solution are having .net 3.5 projects.

When i compile it through Visual studio it works. If i build the same using Msbuild it fails.

Following is the compilation issue:

error : Compilation failed. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. Exception from HRESULT: 0x80131515

Even i tried with changing

toolsversion to 3.5

through additionalproperties of item. [ I am using Msbuild task to build my solution]

Our Msbuild task looks like below.

<Target Name="BuildDotNETSolutions" Condition="'$(Group)' != ''" DependsOnTargets="Init;GetNextVersionNumber">
    <!-- Complie solutions -->
    <!-- Version property is useful for changing the Wix Msi version-->
    <MSBuild Projects="@(Solution)" BuildInParallel="true"
                 Properties="Configuration=$(Configuration);PostbuildEvent=;Version=$(BuildNextVersionNumber)"
                 Condition="'%(Solution.Group)' == '$(Group)' And '%(Solution.Type)' == 'DotNET' And '%(Solution.IsRebuild)'=='$(IsRebuild)'">

      <Output
                      TaskParameter="TargetOutputs"
                      ItemName="BuildOutputs" />
    </MSBuild>

We are passing solutions through properties file like below

<Solution Include="$(Implementation)\MultiEvent.csproj;">
      <Group>Event</Group>
      <AdditionalProperties>
        ReferencePath=$(Implementation)\References;
        ToolsVersion=3.5;
      </AdditionalProperties>
      <IsRebuild>True</IsRebuild>
      <Type>DotNET</Type>
    </Solution>
1

There are 1 best solutions below

0
On

I don't know if you happen to have any script-runner that runs MSBuild. Personnally, I'm using NAnt and everything is working fine. I've read (somewhere) that MSBuild sometimes do stupid things and by adding the property "TrackFileAccess" and set it to "false" helps a lot. In my case, it fixed the problem.

If it can be of any help, I've included my NAnt build task. I hope it can be useful to you.

<!--*******************************************************************************
Runs MSBuild to build the project solution

Arguments:
${MSBuild.exe}:  Path to MSBuild.exe
${project.solution}: the solution name to build
${buildconfiguration}: The build configuration to trigger the build
${build.dir} : The directory where to put builded files

********************************************************************************-->
<target name="run.msbuild" description="Rebuilds a given solution file">

<echo message="Rebuilding Solution ${project.solution}" />
<echo>${MSBuild.exe}</echo>

<exec program="${MSBuild.exe}">
       <arg value="${project.solution}"/>
    <arg line="/property:SignAssembly=${project.sign},AssemblyOriginatorKeyFile=${project::get-base-directory()}\${project.signature.file}" />
    <arg line="/property:OutDir=${build.dir}" />
    <arg line="/property:TrackFileAccess=false" />
    <arg line="/property:DebugType=${debug.type}" />
    <arg line="/property:Platform=&quot;Any CPU&quot;" />
    <arg line="/nologo" />
    <arg line="/verbosity:minimal" />
    <arg line="/property:Configuration=${buildconfiguration}"/>
</exec>

in the case of a Development build, I set the following params :

<property name="buildconfiguration" value="Debug"/>
<property name="debug.type" value="full" />