简体   繁体   中英

exclude certain projects from using Directory.Build.props

i have a new visual studio solution that has around 350 projects. it takes visual studio a lot of time to compile the .sln file so i implemented Directory.Build.props to avoid copying of references that are not needed to copy to the local directory so the build can be made quicker. below is the code that im using inside the Directory.Build.props file under the root folder.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
  <Reference>
    <Private>False</Private>
  </Reference>
  <ProjectReference>
     <Private>False</Private>
  </ProjectReference>
</ItemDefinitionGroup>
</Project>

since i placed Directory.Build.props under root folder it is being applied for all projects.

Question:: how can i exclude few projects from applying Directory.Build.props so that the references can be copied to the local.

in short i want the Directory.Build.props to be applied to only 300 projects under the solution file remaining 50 projects need to be excluded from this

how/where can i write a condition in the above code that will exclude certain projects being affected by this code

I had to work around this in a bit of a hacky way.

In my example, there was a custom analyzer project I wrote that I did not want included in another set of projects. I ended up writing something like this in my Directory.Build.props :

<Project>
  ...

  <Choose>
    <When Condition="$(MSBuildProjectName)!='Analyzer' AND ...">
      <ItemGroup>
        <ProjectReference Include="..\Analyzer\Analyzer.csproj">
          <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
          <OutputItemType>Analyzer</OutputItemType>
        </ProjectReference>
      </ItemGroup>
    </When>
    <Otherwise>
       ...
    </Otherwise>
  </Choose>

  ...
</Project>

Where I filled in ... with the projects I wanted it to skip.

I understand this may not be the exact answer you were looking for, but I did a ton of research and was also unable to find any way to do it the way you described. The stuff I have posted was the only way I was able to achieve the ability to exclude certain things from being applied to specific projects by filtering via name. I know that this is hacky and sucks, but it's the only thing that was able to work for me.

Also note that <Otherwise></Otherwise> may be turned into <Otherwise /> possibly, and may even be optional altogether. I left it there so that you could place stuff inside of it if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM