MSBuild,不接受到lib目录的OutputPath [英] MSBuild, OutputPath to a lib directory is not honoured

查看:100
本文介绍了MSBuild,不接受到lib目录的OutputPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在花了几个小时,但我根本不明白:

I spent hours now but I simply don't get it:

为什么VS快速更新检查"不支持 lib 子目录? 如果设置了库的lib输出目录,则解决方案将始终重新生成-无论是否进行更改都无关紧要.如果 \ lib 子目录被删除,它将起作用.为什么?

Why is a lib sub directory not honoured by the VS "fast up-to-date check"? If a lib output dir for libraries is set, the solution is always rebuild - if changes have been made or not does not matter. If \lib sub dir is removed it works. Why?

这是我到目前为止测试过的内容:

Here is what I tested so far:

请参阅下一个代码段.那是完美的作品.如果要求多个从属项目进行多次构建,则即使没有进行任何更改,它们实际上只会构建一次. Visual Studio FastUpToDateCheck启动.

Refer to the next code snippet. That one works perfectly. If several dependent project are asked to build multiple times they actually build only once if no changes have been made. The Visual Studio FastUpToDateCheck kicks in.

但是如果您更改行

<OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)</OutputPath>

<OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\lib\</OutputPath>

它不断地重建.有什么想法吗?

it constantly rebuilds. Any ideas why?

.sln文件旁边的ComponentBuild.props

ComponentBuild.props located next to .sln file

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <IntermediateOutputPath>$(SolutionDir)obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
    <UseCommonOutputDirectory>False</UseCommonOutputDirectory>
    <DisableFastUpToDateCheck>false</DisableFastUpToDateCheck>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(OutputType)' == 'Library' ">
    <!-- To distinguish by \lib\ does not work, a rebuild is triggered since the up-to-date check fails -->
    <!-- <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\lib\</OutputPath> -->
    <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)</OutputPath>   
    <OutDir>$(OutputPath)</OutDir>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(OutputType)' == 'Exe' ">
    <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
  </PropertyGroup>
</Project>

该文件包含在Import Microsoft.CSharp.targets之前的csproj文件中:

The file is included in csproj files just before Import Microsoft.CSharp.targets:

.csproj文件:

.csproj file:

    <!-- position of include is important, OutputType of project must be defined already -->
    <Import Project="$(SolutionDir)ComponentBuild.props" Condition="Exists('$(SolutionDir)ComponentBuild.props')" /> 
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    <PropertyGroup>
      <PostBuildEvent>
      </PostBuildEvent>
    </PropertyGroup>

我测试的越多,行为就越怪异. 我创建了两个简单的库项目A和B.B依赖于A.我在上面添加了import和FastUpToDateCheck的工作. 将lib路径添加到库outputtype后,它在没有其他更改的情况下有效.但是,在清理lib B项目时,所有后续构建都将重新生成项目B.

The behaviour becomes more weird, the more I test. I created two simple library projects A and B. B depends on A. I added above mentioned import and the FastUpToDateCheck works. After adding lib path to the library outputtype, it works when nothing else is changed. But when lib B project is cleaned, every subsequent builds do rebuild project B.

将lib路径也添加到exe输出类型时. FastUpToDateCheck再次起作用.

When adding lib path to the exe outputtype as well. The FastUpToDateCheck works again.

然后,我再次从输出类型exe中删除了lib路径,但是FastUpToDateCheck仍然出奇地起作用-始终如此.即使清理构建,更改类或删除所有obj和bin文件夹.

Then I removed the lib path again from output type exe, but the FastUpToDateCheck surprisingly still works - always. Even when cleaning the build, changing a class or deleting all obj and bin folders.

但是,一旦我也从lib输出类型中删除了lib路径,即我将所有设置都恢复为原始状态,即失败.每次都会重建.诊断输出的第一行是

BUT as soon as I removed the lib path from the lib outputtype as well, i.e. I set back all to the original state, it FAILS. It rebuilds every time. The first line of the diagnostic output is

项目"ClassLibrary1"不是最新的.缺少输出文件 'c:\ Users \ hg348 \ Documents \ Visual Studio 2015 \ Projects \ BuildTest \ bin \ Debug \ AnyCPU \ lib \ ClassLibrary1.dll'

Project 'ClassLibrary1' is not up to date. Missing output file 'c:\Users\hg348\Documents\Visual Studio 2015\Projects\BuildTest\bin\Debug\AnyCPU\lib\ClassLibrary1.dll'

即使不再设置,它仍会查找lib路径. 我认为其中涉及一些令人讨厌的缓存.

It still looks into lib path even though it isn't set any more. I think there is some nasty caching involved.

有人可以验证吗?

推荐答案

好吧,如上所述,我的测试得出了答案: 它在Visual Studio(VS)中进行缓存,该缓存在更改输出路径后触发生成.在更改输出路径和可能的输出目录之后,Visual Studio仍在旧目录中查找其FastUpToDateCheck.

Well, my tests as described above lead to the answer: It is caching in Visual Studio (VS) which triggers the builds after changing the output path. After making changes to the outputpath and probably outdir as well, Visual Studio still looks in the old directory for its FastUpToDateCheck.

关闭并重新打开解决方案有助于清除VS缓存.在某些情况下,有必要删除隐藏文件夹.vs中的隐藏文件.suo. 这解决了上面问题中给出的样本文件中所述的所有问题.

Closing and reopening the Solution helps already to clear the VS cache. In some cases it is necessary to delete the hidden file .suo in hidden folder .vs This solves all problems stated in the sample file given in the question above.

我最终的导入文件如下:

My final import file looks like this:

<?xml version="1.0" encoding="utf-8"?>
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

      <!--  Note that VS caches settings, to be sure the FastUpToDateCheck works
                * reopen the solution after 
                    - changing properties
                    - after adding a platform config
                    - after adding references to projects
                * close VS and remove the hidden file 
                  <solution folder>\.vs\<solution name>\v14\.suo   after changing IntermediateOutputPath,
                  (You have to enable "how hidden files" in windows file explorer)
                * After updating App.config do a random change in any .cs source file too, 
                  otherwise FastUpToDateCheck fails
      -->

      <PropertyGroup>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

        <IntermediateOutputPath>$(SolutionDir)obj\$(Configuration)\$(Platform)\$(MSBuildProjectName)\</IntermediateOutputPath>

        <!-- if true, don't copy output files of referenced assemblies, since everything builds to the same folder. -->
        <UseCommonOutputDirectory>true</UseCommonOutputDirectory>
        <DisableFastUpToDateCheck>false</DisableFastUpToDateCheck>
      </PropertyGroup>

      <PropertyGroup Condition=" '$(OutputType)' == 'Library' ">

        <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\lib\</OutputPath>
        <OutDir>$(OutputPath)</OutDir>
      </PropertyGroup>

      <PropertyGroup Condition=" '$(OutputType)' == 'Exe' ">
        <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\</OutputPath>
        <OutDir>$(OutputPath)</OutDir>
      </PropertyGroup>


      <!-- sets "Copy Local" property of references to false on reopen of solution
           don't copy output files of referenced assemblies, since everything builds to the same folder -->
      <ItemDefinitionGroup>
        <Reference>
            <Private>False</Private>
        </Reference>
        <ProjectReference>
            <Private>False</Private>
        </ProjectReference>
      </ItemDefinitionGroup>

  </Project>

这篇关于MSBuild,不接受到lib目录的OutputPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆