This project is read-only.
2

Closed

Update .csproj Import during Nuget package install

description

Recently, I noticed a Nuget package for StyleCop.

http://nuget.org/packages/StyleCop.MSBuild

This is great. It automates much of the process of upgrading StyleCop when hosted per project.

But, it would be nice if the Nuget package could add the appropriate <Import> statement to all selected C# Projects. With Nuget packages now embedding the version in their package folder to allow multiple versions of the same package, it means that referencing the new StyleCop targets file is a manual process with each upgrade.

<Import Project="$(MSBuildProjectDirectory)..\packages\StyleCop.MSBuild.4.7.14.0\StyleCop.Targets" />

I think these customizations are done with PowerShell inside a Nuget package.

http://www.codeproject.com/Articles/209522/PowerShell-Script-Examples-for-NuGet-Packages
http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference

Unfortunately, the examples above do not interact directly with the .csproj file but rather the DTE environment.
Closed May 12, 2012 at 11:05 AM by andyr
.

comments

andyr wrote Mar 24, 2012 at 12:32 AM

Its not my nuget package so I can't fix/change it here.

eddie_butt wrote Mar 27, 2012 at 9:35 PM

My mistake. The Author on Nuget.org is listed as "Andy Reeves". When I saw "andyr" as listed on the People page here, I assumed that there was collaboration. I wonder how I contact the Owner, "adamralph", and give him the feedback?

andyr wrote Mar 28, 2012 at 9:20 AM

Hopefully Adam will be adding that code directly into the stylecop build here very soon

adamralph wrote Apr 12, 2012 at 6:56 AM

I'll take a look at those examples and see if I can build this in. I agree - this would be a great feature. Adding the imports manually is rather tedious, specially if a solution has many projects. Btw - the source for the package is hosted at https://bitbucket.org/adamralph/stylecop-msbuild - I'll gladly take pull requests. At some point, as Andy mentioned, I will add this to the main StyleCop build here on CodePlex.

adamralph wrote Apr 13, 2012 at 7:46 AM

FYI I've started working on this on an 'autoimport' branch - see https://bitbucket.org/adamralph/stylecop-msbuild/changeset/876930465a02#chg-tools/Install.ps1

adamralph wrote Apr 14, 2012 at 5:51 PM

I've pushed a pre-release version to Nuget which seems to work - see http://nuget.org/packages/StyleCop.MSBuild/4.7.17.1-beta1

It would be great if those interested could give this a try and let me know if it works OK. My testing so far has been successful. One thing I haven't tested yet is whether it works with Nuget package restore enabled.

adamralph wrote Apr 14, 2012 at 6:00 PM

I've hardly used Nuget package restore, so I'm not familiar with any subtleties, but I've tried testing 4.7.17.1-beta1 with Nuget package restore enabled and it seems to work OK.

adamralph wrote Apr 15, 2012 at 1:33 PM

I've just pushed out http://nuget.org/packages/StyleCop.MSBuild/4.7.17.1-beta2 with refactored PowerShell scripts. This is the version I will be testing this week with a view to releasing it as a stable version towards the end of the week.

I'm a bit of a PowerShell n00b but I think the scripts are a bit better now. If any PowerShell expert fancies having a look I'll more than gladly merge a pull request which makes them nicer.

adamralph wrote Apr 17, 2012 at 8:28 PM

Package version 4.7.17.1 has now been published and includes this feature. FYI I've posted on my blog about this release at http://adamralph.blogspot.com/2012/04/introducing-stylecopmsbuild.html

eddie_butt wrote Apr 23, 2012 at 2:09 AM

Thanks @adamralph!

I just tested on a new project and everything is working as advertised for me. I took a peek at the PowerShell scripts and, through my beginner eyes, I understood what it was doing and didn't see any obvious ways to improve it.

We'll start using it for real shortly.

andyr wrote May 11, 2012 at 5:21 PM

Hi. Is there any action for the StyleCop devs on this item?

adamralph wrote May 12, 2012 at 9:27 AM

Hi Andy,

No action required. I guess you can close this workitem.