how to set all projects in solution to copy local

2019-08-09 09:32发布

问题:

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