user729893
user729893

Reputation: 45

MSBuild custom rules

When MSBuild happens, I want it to fail if the sharepoint project (WSP from that project) is targeted to GAC.

ie. just before packaging I want to check the feature.xml or anyother .xml files where the package is targeted to for this.

What are the possible ways to achieve this ? I dont have any exp. in custom MSBuild tasks. Is this doable ?

Upvotes: 2

Views: 375

Answers (1)

What I suggest would be the following:

Create a program, that accepts the path to your project as a parameter and analyzes it for the errors you define yourself. When your program finds and error, it will simply output an error to the console in one of the following formats:

error: <message>
<filename>: error: <message>
<filename> (<line>): error: <message>
<filename> (<line>,<column>): error: <message>

You can replace the word "error" with "warning". When you use this specific format, then the errors (or warnings) will appear in the Visual Studios error list when you compile using VS. Passing the filename and the line will enable the "double-click jump to error" feature.

Next you open your project file and add an AfterBuild target. In this target you use the Run command to call your own application and pass on your project path. Make sure to set the "ContinueOnError" attribute to false.

Now whenever you build your custom target will be triggered. Your custom target will call your application which will analyze your project. When your application outputs an error, MSBuild will pick it up and cancel continuation and mark the build as failed.

You could also use a MSBuild task for this, but I'd suggest you not to. A msbuild task will be loaded to the AppDomain of your Visual Studio, locking the Assembly. When you want to replace it (e.g. because you changed your analyzing rules) you first have to quit Visual Studio to unlock the file. This will be really annoying when working with a source control system where people just want to update the current files without worrying if an assembly is locked or not.

I run this principle really successfully with analyzing one of our project as part of the build, as well as creating a proxy client for our own web service as part of the build.

Upvotes: 1

Related Questions