Can I call a MSBuild Task from Mono XBuild? - msbuild

Can I call a MSBuild Task from Mono XBuild?
http://msdn.microsoft.com/en-us/library/ms126274.aspx
http://www.mono-project.com/Microsoft.Build

Yes, you can. Same way as you would do it with msbuild, with UsingTask .
You can use AssemblyFile or AssemblyName attribute.
http://msdn.microsoft.com/en-us/library/t41tzex2(VS.90).aspx

Related

Set PackageId at package time?

I'm trying to figure out how to specify a packageId at build or specifically at package time. I have the following in my csproj which works well for creating packages locally for the purposes of testing. We are using Azure DevOps build pipelines to build and pack our nuget packages and I would like to be able to set the packageId as a task or msbuild parameter within the build pipeline.
Does anyone have suggestions on how I could acheive this?
Thanks,
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);Dependencies</TargetsForTfmSpecificBuildOutput>
<Version>0.1.0.5</Version>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyName>MyAssembly</AssemblyName>
<RootNamespace>MyAssembly</RootNamespace>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<PackageId>MyAssembly.Test</PackageId> <----- set at package time
<FileVersion>1.0.0.0</FileVersion>
<PackageLicenseUrl>https://my.domain.xyz/license.pdf</PackageLicenseUrl>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<Description>A useful description.</Description>
<Company>XYZ</Company>
<Authors>UiPath</Authors>
<PackageIconUrl>http://my.domain.xyz/favicon.ico</PackageIconUrl>
Set PackageId at package time?
The answer is yes.
According to the document MSBuild pack target inputs, we could to know the PackageId is supported to be set at build time.
Note:
I saw that you set the property GeneratePackageOnBuild to true, so visual studio will generate the nuget package automatically.
So, if you are not use extra dotnet pack task to package your package, you add msbuild argument -p:PackageId=<PackageId> with your dotnet build task, like:
dotnet build -c Release -p:PackageId=<PackageId>
If you have another dotnet pack task to package your package, #Martin`s answer is correct.
Note2:
When we use the option -p:PackageId to change the package ID, but the AssemblyName is not changed. So the Package ID of the generated package is not consistent with its AssemblyName. We need to pay more attention when we use this nuget package. Or we could also change the AssemblyName to make it match the package id by the option -p:AssemblyName=<AssemblyName>
Hope this helps.
Did you try calling?:
dotnet pack -c Release -p:PackageId=The.Other.Packge.id
Or the equivalent in the .NET Core CLI task
You could modify the XML of the csproj after clone and before build using the File Transform task:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/file-transform?view=azure-devops

Run SingleFile Generator through MSBUILD

i have created a Custom tool (SingleFile generator) using IVsSingleFileGenerator. Which takes "xyz.Resx" file as input and generate "xyz.Designer.resx.cs" file. This file can be generated on building/Saving the Application through IDE.
Issue is, I have given the Custom Tool Property for any .Resx file and build the application through MSBUILD. Now I am unable to build/
generate the "Designer.resx.cs" file.
How to prepare a Custom Task to run this custom tool through MSBUILD.
plz help in doing the same.
Thanks in advance.
I don't have much knowledge about this custom tool IVsSingleFileGenerator which you are using. To execute it in MSBuild you may need targets for the same given by them to generate the resx.cs file from .resx file. Or you may add a commandline call of this tool in your MSBuild script and try it.
I don't think you can run CustomTool from MsBuild. Since you're the one that wrote the tool, I would definitely suggest to create msbuild task and start using it.
Here are some ideas how to do that:
http://msdn.microsoft.com/en-us/library/t9883dzc.aspx
http://blogs.msdn.com/b/msbuild/archive/2006/01/21/515834.aspx
Another approach would be to write executable, but that will be less efficient.
Here is how you call executable from msbuild
<Target Name="your-target-name" AfterTargets="the-starting-point-of-your-target">
<Exec Command="your_exutable-here parameters_here" WorkingDirectory="your_working_folder" />
</Target>
Third approach would be to write inline msbuild task
http://blogs.clariusconsulting.net/kzu/writing-inline-msbuild-tasks-in-c-for-one-liners/
I hope that helps

Can MSBuild ignore a project reference? (BuildProjectReferences doesn't work)

I am trying to make a build script for a .NET solution which consists of several c# projects and one custom project. The custom project can be build by devenv but msbuild chokes on it.
I would like MSBuild to ignore the custom project because I'm already building it with an Exec task. I actually need MSBuild to not even open the custom .proj file because it's in JSON format and thus causes MSBuild to crash out.
The /BuildProjectReferences=false switch doesn't work. MSBuild still tries to read the custom project file. Is there any way around this?
This question stemmed from a project which had a SilverFrost Fortran project alongside several c# class libraries. The solution would only compile using devenv. Msbuild would throw an error on the Fortran project because it doesn't use the standard .csproj format.
Even with /BuildProjectReferences=false, msbuild would try to read the Fortran project and throw an error. The workaround I discovered was to wrap the msbuild task in an nant task which does the following:
Invokes the Fortran command line compiler
Removes all references to the Fortran project from other .csproj projects using the xmlpoke task
Replaces said references with a direct dll reference to the Fortran compiler output
Invokes Msbuild on the modified solution
Instead of building your solution once by MSBuild, try to build each project one by one. In this case, you can ignore the desired project. You can also define your own "Exec"-based build in this new script.
In your project that uses the custom project, can you right click on the Project Dependencies and remove the custom project from the list? You can refer to the custom project's binary output instead.

Nant msbuild task with .net 4.0 rc

How do I need to indicate to the msbuild task in my nant script that it should use .net 4.0 rc?
I think the latest NAnt/NAntContrib defaults to .NET 3.5, so you'll have to change that to 4.0. There is a NAnt property to handle that (<property name="nant.settings.currentframework" value="net-4.0" />), which should go near the top of your NAnt build file.
Next, you'll need to go into your NAnt's configuration file and add the 4.0 node, so that NAnt (and by extension NantContrib) are aware of the new CLR version.
The first option is to change the executable that MSBuild task uses. According to the doco this is a framework property so you would need to change it in the main nant config file rather than in you're individual script, and you would have to do it on every machine you plan on building the script on.
The other option is to use the exec task instead. This question and answer should help with that.
EDIT: Forgot to mention the directories MSBuild is in. To change versions just use a different MSBuild.
2.0: %windir%\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe
3.5: %windir%\Microsoft.NET\Framework\v3.5\MSBuild.exe
4.0b2: %windir%\Microsoft.NET\Framework\v4.0.21006\MSBuild.exe

Custom MSBuild task with dependencies

I have written an MSBuild task that makes use of third-party assemblies.
When I use the task in my project, MSBuild complains that it can't load the third-party assemblies (not surprisingly).
Where should I place the third-party assemblies so that they are available to MSBuild. I tried adding project references to them without success.
I'm not sure if I expressed my problem very well, but now I've found the solution.
In my .proj file, I reference my custom task with the following syntax...
<UsingTask AssemblyFile="..\lib\MyCompany.MSBuild\MyCompany.MSBuild.dll" TaskName="CreateDatabase" />
My CreateDatabase task relies on various 3rd-party assemblies. However, some of these are only referenced via reflection, so weren't included by default in the folder "..\lib\MyCompany.MSBuild".
I had been trying to get the task to work by placing the required assemblies in the same directory as the .proj file invoking the task.
However, what I should have been doing was putting the assemblies in the referenced task directory "..\lib\MyCompany.MSBuild\".
Simple!
You could add them to the GAC (Global Assemby Cache). This only works if it is strongly named.
You could also make sure that you have marked them with copy local = true when you added the reference in the project.