Red Gate forums :: View topic - Tip: MSBuild support the easy way
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 5
SmartAssembly 5 forum

Tip: MSBuild support the easy way

Search in SmartAssembly 5 forum
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
Jump to:  
Author Message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Thu Jun 24, 2010 5:52 pm    Post subject: Tip: MSBuild support the easy way Reply with quote

There is a nice description on how to use SA with MSBuild on the red-gate site (http://www.red-gate.com/supportcenter/Content.aspx?p=SmartAssembly&c=SmartAssembly/help/5.0/SA_UsingSmartAssemblyWithMSBuild.htm&toc=SmartAssembly/help/5.0/toc1032253.htm) but there is an much easier way which comes handy when you have multiple projects or simply no mood to add all the stuff to your project file.

Create a file called "SmartAssembly.targets" in the location of your preference (I'd suggest the SA installation folder or a common path to your projects). In this file you paste the following:
Code:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <UsingTask TaskName="SmartAssembly.MSBuild.Tasks.Build" AssemblyName="SmartAssembly.MSBuild.Tasks, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7f465a1c156d4d57" />
   <Target Name="BeforeBuild" Condition=" '$(Configuration)' == 'Release' ">
      <CreateProperty Value="true">
         <Output TaskParameter="Value" PropertyName="RunSmartAssembly" />
      </CreateProperty>
   </Target>
   <Target Name="AfterCompile" Condition=" '$(RunSmartAssembly)' != '' ">
      <Copy SourceFiles=".\obj\Release\$(TargetFileName)" DestinationFiles=".\obj\Release\$(TargetName).temp$(TargetExt)" />
      <SmartAssembly.MSBuild.Tasks.Build ProjectFile="$(SolutionDir)Build\$(TargetName).{sa}proj" OverwriteAssembly="True" />
   </Target>
</Project>


In your project file you add just one single line:
Code:
<Import Project="$(YourPathToSA)\SmartAssembly.targets" />

instead of adding all the code mentioned in the link above. Take care to store your SA project files in the $(SolutionDir)\Build\ folder with the exact name of the target assembly. If your assembly is "MyTestAssembly.dll" then the sa project should be named "MyTestAssembly.{sa}proj"

And thats it already. With that single line in all your project files, all your release builds will be protected by SA.

One note: I added a <copy> step to make your life easier if you ever need to change the sa-project settings in the sa GUI again. It will make a copy of the unprotected assembly into the same obj\release folder. So you can simply rename it, run the GUI and make your changes and then rebuild. If you dont need this, just remove the <copy> step.

One could now improve this to include MarkAsReleased depending on the $(Configuration), which would allow you to make an additional "Release" config for you projects for the "real" release which will be shipped. No need to mark all release builds with MarkAsReleased, right?

cheers
Back to top
View user's profile Send private message MSN Messenger
Alex.Davies



Joined: 02 Dec 2008
Posts: 335
Location: Cambridge, uk

PostPosted: Fri Jun 25, 2010 4:01 pm    Post subject: Reply with quote

Nice tip, I know that the SQL Source Control team in red gate do something very similar. Stickied.
_________________
Alex
Developer,
Red Gate .NET Tools
Back to top
View user's profile Send private message
rcd.guerra



Joined: 13 Sep 2010
Posts: 10

PostPosted: Wed Sep 15, 2010 10:39 am    Post subject: Reply with quote

Very nice post!

With this approach i still need to have a .saproj file for each project or dependency right ?

Thanks a lot indeed!

Ricardo
Back to top
View user's profile Send private message
Linda Hawksworth



Joined: 25 Jun 2007
Posts: 192

PostPosted: Wed Sep 15, 2010 2:54 pm    Post subject: Reply with quote

Yes, you will still have to have a project for each project/dependency. There is currently no way to automate this.
Back to top
View user's profile Send private message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Wed Sep 15, 2010 3:00 pm    Post subject: Reply with quote

Well Linda, depending on your needs there actually IS a way to make it easier.

For example, I've got a set of assemblies which I pass through SA, around 15 dll's, some depending on others, some standalone. But I use the same project file for all of them. How? Hand-editing the project file including ALL dependencies into the SA project. SA chooses which of the dependencies are needed and ignores the rest. Less than optimal, but it works and makes things easier.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies. All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group