Use MSBuild Properties in T4 Templates - t4

I am using MSBuild to generate some files using T4 and I was wondering if it would be possible to reference and use MSBuild properties within the T4 template?
I want to do something like this snippet:
Revision: <#=$(Revision)#>
This throws an error:
error CS1056: Compiling transformation: Unexpected character '$'
I'd prefer not to have to wrap the properties in a custom DLL and reference a C# class as a T4 property.
Any help would be much appreciated.

It should be possible to pass $(Revision) value via TextTransform command line -a option.
Add something like this into your template:
[<#= this.Host.ResolveParameterValue("", "", "RevisionParameter") #>]
And into MsBuild script:
TextTransform -a !!RevisionParameter!$(Revision)

You may use ResolveAssemblyReference, for example :
Revision: <#=Host.ResolveAssemblyReference("$(Revision)")#>

Related

Does MSBuild also link?

I have used msbuild from commandline to build my sln projects. But I can't find the exe output anywhere.
Can anyone explain me what I am doing wrong?
Thanks
If you use MSBuild command line to build your project, it can specify the outputpath of the project.
Use like this -p:outputpath=C:\test, C:\test is the new output folder of your project.
More msbuild command line arguments, you can refer to this document.
So you should use like this:
msbuild xxx\xxx.sln -t:build -p:outputpath=xxx(specified new output path)

Skipping dependency wixproject using msbuild command line

I am building a wixproject using Visual studio solution on Configuration= Release,Platform=x64 by unchecking x86 platform to skip some dependency wix projects.
Is there a way to do the same using MSBuild command line?
Skipping dependency wixproject using msbuild command line
Just like stijn said, you can specify the property in the command line when you build the project/solution file.
As we know, the property Platform= project-level property, which we could set or override the specified project-level properties by -property:name=value. Name is the property name and value is the property value.
Check the document MSBuild command-line reference for some more details.
So, to resolve this issue, you just need pass the property Platform=x64 in the command line, like:
MSBuild YourProjectPath.wixproj /property:Configuration=Release /property:Platform=x64
or use shorter form:
MSBuild YourProjectPath.wixproj /p:Configuration=Release /p:Platform=x64
Hope this helps.

How to override all project properties for Visual Studio 2010 in msbuild through Powershell

I am trying to write a script where automatically build in 30+ Visual Studio 2010 (.sln) through PowerShell script using Msbuild command line.
I am able to build the build the modules, but I have some dependency and specific project setting for all 30+ modules. Project properties for all 30+ modules are same. So I want to pass all the project properties once in the script to set for all modules for building automatically.
But,
I am not able to pass all the project setting where as only 3 parameters I am able to pass such /t:build /p:configuration:Debug /p:TargetPaltform=x86.
Issue: I want to pass all project properties as arguments for msbuild in my pwoershell script.
Could you please provide some syntax or idea how can I pass more project properties parameters as command line?
Example Parameters List:
Output Directory
Intermediate Directory
Include Directories
Library Directories
Output File and sub sections. etc.

How to suppress warning output in CruiseControl.net

I am using cruisecontrol.net to build and deploy as part of the continuous integration. During the build process, it shows many warnings as shown below:
Read-only property "CCNetLabel" cannot be overwritten.
Log\ILogRecord.cs(10,18): warning CS0108: 'My.Interface.Log.ILogRecord.Level' hides inherited member 'My.Interface.Log.ILogTuple.Level'. Use the new keyword if hiding was intended. [d:\Build\mysite\abc\Technology.Interface\Teach.Interface.csproj]
These are benign warnings with no bearing on the build process. Is there a way to suppress them?
Thanks
Try these parameters in your msbuild task in your ccnet.config file. It passes these to the msbuild executable.
<buildArgs>/consoleloggerparameters:ErrorsOnly /verbosity:minimal</buildArgs>
They are documented in the msbuild command line reference
https://msdn.microsoft.com/en-us/library/ms164311.aspx

How do I target a specific .NET project within a Solution using MSBuild from VS2010?

I have an MSBuild command line that can build an entire solution. It looks something like this:
msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:Build
I know that for C++ Solutions, specific projects can be targeted using the following syntax:
msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:Folder\SomeCppProject;Build
I'm trying to achieve the same thing for .NET projects within a solution. This does NOT work:
msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:SomeDotNetProject;Build
Does anyone know how to target a specific project within a solution using MSBuild on the command line for .NET projects? I know I can create a custom MSBuild project to achieve what I'm after, but I need to share the solution and projects with Visual Studio.
Thanks!
-Sean
You'll need to specify any solution folders in the Visual Studio solution file, and replace any "." in the project name with "_":
msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /t:Folder\Project_Name
For example, if you have a project in the solution folder "Deploy" named "MyApplication.Deployment.csproj", you'll need
msbuild SomeSolution.sln /p:Configuration:CustomDebug;Platform=OurPlatform /t:Deploy\MyApplication_Deployment
Incidentially this is a solution folder, as displayed in Visual Studio, not a file system folder: those are ignored.
You can use the following commandline for building your project using msbuild from commandline
msbuild Solution.sln /p:Configuration=Release;Platform=x86 /t:ProjectName:Rebuild
Invoke MSBuild on the project file instead of the solution file (ref.msbuild /?)
msbuild SomeDotNetProject\SomeDotNetProject.csproj /p:Configuration:CustomDebug;Platform=OurPlatform /nodeReuse:false /maxcpucount:4 /t:Build

Resources