how to set all projects in solution to copy local false

北城以北 提交于 2019-12-24 11:30:24

问题


is there a quick way to mark all the solution projects references as Copy local false? is there some tool that does that? it's pretty messy to mark about 200 projects manually


回答1:


You could use xsl to transform the project file to add False (this is what copy local false does)

Here's an example xslt file

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cs="http://schemas.microsoft.com/developer/msbuild/2003"
exclude-result-prefixes="cs"> 

    <xsl:output method="xml" indent="yes" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="*"> 
    <xsl:copy> 
        <xsl:apply-templates select="@*|*|text()|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="cs:Project/cs:ItemGroup/cs:Reference"> 
        <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
          <xsl:if test="not(./cs:Private)">
            <Private>False</Private>
          </xsl:if>

    </xsl:copy>
    </xsl:template> 

    <xsl:template match="@*| text() | node()"> 
        <xsl:copy>
             <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
    </xsl:template>     
</xsl:stylesheet> 



回答2:


I have a tricky way to do it, but it is always manually

Suppose you have two projects

Pull all your references, press shift and select your first reference then keep holding shift and select the last reference of your first project

Release the shift button, press ctrl button and select you first reference of your second project, then you press ctrl and shift button at the same time and select your last reference of your second project

It should be like this:

Finally you can set Copy local property to false to all your selected references

IDE: VS2013 french




回答3:


Yes, there is a realy easy and quick way, starting with msbuild v 15. You can copy a single file called Directory.Build.props in the root folder that contains your source:

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

Nothing more to do! More info see https://stackoverflow.com/a/50755479/1196586



来源:https://stackoverflow.com/questions/27236089/how-to-set-all-projects-in-solution-to-copy-local-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!