Project manipulation from an add in

I need to change the value of Copy local based on the active configuation, below is the solution I was given to do this, but it requires I manually edit the project file.

This is where the add in comes into play, I am able to get the list of references and such from the project object, so I've got it started at least. However, I'm having trouble with the following:

1) How to add the CopyLocal to the propert Configuration once I have the config (know how to get that)

2) How to retreive the CopyLocal from teh Configuration (prob be obvious once item 1 is working)

3) How to set the Private property to $(CopyLocal) once the configs have the value all set up

4) How to know that private is set to $(CopyLocal) vs True/False.

Thanks
Wayne


You can conditionally set a property on a basis of current configuration:

Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "

At the top of your *.csproj or *.vbproj you'll find a per configuration section, so you can just add a new property to that section:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

<CopyLocal>true</CopyLocal>

</PropertyGroup>

Using this you set the Private attribute on the references on the basis of the current configuration. If the private attribute is true the "CopyLocal" is set to true.

<ProjectReference Include="..\MyProj.csproj">
<Project>{A4E9A2C2-....}</Project>
<Private>$(CopyLocal)</Private>
</ProjectReference>

Thanks,

Vladimir



Answer this question

Project manipulation from an add in

  • Subasree

    Ok, that makes sense, but how to store what files my add in is going to manage I don't want to change the copy local for everything, just certian items, and need that to be tracked with the project as other team members work on the same project.

    I'm off to see if there is an event for the Build change.

    Thanks
    Wayne

  • Randall Ulloa

    Hi,

    AFAIK, the CopyLocal property is configuration-independent. So, your add-in needs to:

    - Detect configuration changes. I'm not sure if there is an event for this.

    - Depending on the active configuration, use VSLangProj.Reference.CopyLocal to change its value. You can get the active configuration using Solution.SolutionBuild.ActiveConfiguration.

    --

    Best regards,

    Carlos J. Quintero

    MZ-Tools: Productivity add-ins for Visual Studio

    You can code, design and document much faster:

    http://www.mztools.com



  • KDavie

    Ok, I've got everything working, but not the way I want too.

    If my add in has to change the copy local when I build, the project has to be checked out of source control. The above example allows the copy local to work even if the project is not checked out.

    So again, is there anyway to modify the project file with an add in so that I can add the copy local flag, and set the private value to my flag

    If nothing straight forward, then I will just deal with the copy local causing the project to be checked out.

    Thanks
    Wayne


  • GMc

    You can use Project.Globals to store custom project data, I think.

    --

    Best regards,

    Carlos J. Quintero

    MZ-Tools: Productivity add-ins for Visual Studio

    You can code, design and document much faster:

    http://www.mztools.com



  • Antao Almada

    CopyLocal is a project property, meaning that the value is stored within the project file. When any modifications are made to the project that immediately or in the future will cause the project file to be modified, then the file must be checked out. There are no ways around this, the file must be modified.

    Craig



  • vze2dytt

    http://www.microsoft.com/Downloads/details.aspx familyid=79C7E038-8768-4E1E-87AE-5BBBE3886DE8&displaylang=en

    Found the above, some REALLY nice examples of VS automation, especially the much needed Spell checker for me :)

    There are a few where the addin is storing items in the project, now just to go and pull them apart and try and figure out how they work.

    Thanks for the help and pushes in the right direction.
    Wayne


  • Project manipulation from an add in