的MSBuild,OutputPath到lib目录是不遵守

问题描述:

我现在花了几个小时,但我只是不明白这一点:的MSBuild,OutputPath到lib目录是不遵守

为什么一个LIB子目录不是由VS“快跟上时代的荣幸检查“? 如果设置了库的lib输出目录,解决方案总是重建 - 如果更改已经完成或没有重要。如果\ lib子目录被删除它的作品。为什么?

这是我测试至今:

请参考下面的代码片段。那个完美的作品。如果几个依赖项目被要求多次构建,他们实际上只构建一次,如果没有更改。在Visual Studio FastUpToDateCheck踢。

但是,如果你改变线路

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

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

它不断地重建。任何想法为什么?

ComponentBuild.props毗邻.sln文件

<?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文件:

.csproj的文件:

<!-- 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.我添加了上面提到的导入和FastUpToDateCheck工程。 将lib路径添加到库outputtype后,它在没有其他更改时起作用。但是,当清理lib B项目时,每个后续版本都会重建项目B.

将lib路径添加到exe outputtype时也是如此。 FastUpToDateCheck再次工作。

然后我再次从输出类型EXE中删除lib路径,但FastUpToDateCheck仍然工作 - 总是。即使清理版本,更改类或删除所有obj和bin文件夹也是如此。

但是,只要我从lib outputtype中删除了lib路径,也就是说我将所有设置恢复为原始状态,它就会失败。它每次重建。诊断输出的第一行是

项目'ClassLibrary1'不是最新的。缺少输出文件 'C:\用户\ hg348 \文档\ Visual Studio的 2015年\项目\ BuildTest \ BIN \调试\ AnyCPU \ LIB \ ClassLibrary1.dll'

它仍然看起来到库路径,即使它不再设置。 我认为有一些讨厌的缓存。

有人可以验证这一点吗?

+0

无法重现。据我所知,主要的区别在于你为库添加了\ lib * only *,而exe的输出路径保持不变。如果你将\ lib附加到那一个,会发生什么?与此相关的是,您在这里没有展示的其他项目配置可能是罪魁祸首。 – stijn

+0

是的,我只将它附加到库。我发布的是完整的配置。那个是在csproj文件中导入的。 它似乎与单个项目一起工作。你有没有尝试过2个项目,其中一个项目引用了另一个项目? – Hg347

+0

添加lib路径后,不要忘记在依赖类中进行更改或执行清理。否则,重建将无法被观察到。 – Hg347

那么,我的测试如上所述导致了答案: 它是在Visual Studio(VS)中缓存,它在更改输出路径后触发构建。对输出路径进行更改并可能还有outdir之后,Visual Studio仍会在旧目录中查找其FastUpToDateCheck。

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

我最终导入文件看起来是这样的:

<?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> 
+0

最后,我也找到了有关$(Platform)问题的解决方案。解决方案文件夹中有一个.vs文件夹。这似乎缓存属性设置像IntermediateOutputPath。我关闭了VS,删除了文件'.vs \ \ v14 \ .suo'中的文件.suo,它工作正常! – Hg347