MSbuild 4.0 无法编译.Net 3.5 项目

发布于 2024-12-27 20:42:55 字数 1508 浏览 2 评论 0原文

我正在使用Msbuild 4.0。

在我们的项目中,很少有解决方案拥有 .net 3.5 项目。

当我通过 Visual Studio 编译它时,它可以工作。如果我使用 Msbuild 构建相同的内容,则会失败。

以下是编译问题:

error : 编译失败。无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。 HRESULT 异常:0x80131515

即使我尝试更改

工具版本为 3.5

通过项目的附加属性 。 [我正在使用 Msbuild 任务来构建我的解决方案]

我们的 Msbuild 任务如下所示。

<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>

我们通过属性文件传递解决方案,如下所示

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的憧憬 2025-01-03 20:42:55

我不知道您是否碰巧有运行 MSBuild 的脚本运行程序。就我个人而言,我正在使用 NAnt,一切都工作正常。我(在某处)读到 MSBuild 有时会做一些愚蠢的事情,通过添加属性“TrackFileAccess”并将其设置为“false”会很有帮助。就我而言,它解决了问题。

如果它有任何帮助,我已经包含了我的 NAnt 构建任务。我希望它对你有用。

<!--*******************************************************************************
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="Any CPU"" />
    <arg line="/nologo" />
    <arg line="/verbosity:minimal" />
    <arg line="/property:Configuration=${buildconfiguration}"/>
</exec>

在开发构建的情况下,我设置以下参数:

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

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="Any CPU"" />
    <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" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文