How to setup dynamic groups in MSBuild without Visual Studio ruining them
One of the really annoying things about VS & MSBuild is that while MSBuild is perfectly capable of doing things like this:
<EmbeddedResource Include="WebUI\**\*.*"/>
Visual Studio would go ahead, resolve the expression and then hard code the current values.
That sort of defeat the way I want to make use of it, which would make it frictionless to add more elements. If you do it in a slightly more complex way, VS can’t resolve this easily, so it does the right thing and compute this at build time, rather than replacing with the hard coded values.
Here is how you do it:
<Target Name="BeforeBuild"> <CreateItem Include="WebUI\**\*.*"> <Output ItemName="EmbeddedResource" TaskParameter="Include" /> </CreateItem> </Target>
Comments
What seems strange is that I've already used a wildcard to include all asmx in a web application. See my csproj :
<itemgroup
<content
<content
<content
<content
Perhaps the problem is only related to the <embeddedresource element ?
Does it keep it as dynamic? When I tried it (on both compile & embedded resource), it just killed things
Sorry for the html in my comment. Manually html encoded version :
<ItemGroup>
<Content Include="***.asmx" />
<Content Include="***.ashx" />
<Content Include="***.aspx" />
<Content Include="***.svc" />
</ItemGroup>
and read "to the EmbeddedResource xml element" ?
Yes, it works great when VS compile and on TFS Build also.
My ItemGroup is placed at the end of the csproj, after the two MS imports : Microsoft.CSharp.targets & Microsoft.WebApplication.targets, and before BeforeBuild & AfterBuild targets.
The bonus is that the files are displayed well in the solution explorer.
But I never add or remove solution items using visual studio, as this projet's goal is only to merge other web applications. Perhaps when VS add a file it makes all content references static.
Can I send you my .csproj file ?
Oh, that explains it.
The project I am working on has dynamic & static content, which I edits.
When you make a modification, it seems to trigger the "to hard code" thingie
FYI,
You can place item groups directly in targets with msbuild 3.5 now. The CreateItem task is actually considered deprecated.
I find it more natural to use item groups then the CreateItem task.
MSDN doc that states CreateItem is deprecated as of 3.5.
msdn.microsoft.com/en-us/library/s2y3e43x.aspx
MSDN doc that says ItemGroups can live in Targets as of 3.5.
msdn.microsoft.com/en-us/library/646dk05y.aspx
Can anybody explain what is dynamic group? Maybe your post answers following stackoverflow question:
stackoverflow.com/.../is-there-a-way-to-automat...
Comment preview