We have a number of Xamarin iOS projects that are part of our main solution since we need to ensure that they compile as part of the gated check-in. However most of our developers are not using iOS and hence do not configure a connection to a Mac build agent.
During build locally and on our servers, we see this warning:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets(63,5): Warning VSX1000: No Address and User has been specified in order to establish a connection to a Mac Server, so only the main assembly was compiled for project 'MyProject.iOS'. Connect to a Mac Server and try again to build the full application.
Is there some way of configuring whether this should be a warning, so that we can remove it from the Error List in Visual Studio and the build log from the server? Preferably it should be done in the projects so it could be set once for everyone.
We are using latest Visual Studio 2017 and TFS 2017 Update 2 and build vNext.
A dirty workaround is to override the targets that produce the warning - in my case that's fine as I don't need them.
In our iOS project files I conditionally (if a server address is defined) import a target file, AvoidMacBuildWarning.target, that replaces a number of targets.
Parts of the project file:
...
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets"/>
<Import Project="AvoidMacBuildWarning.target" Condition=" '$(ServerAddress)' == '' " />
<ItemGroup>
...
AvoidMacBuildWarning.target:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="_SayHello">
<Message Text="Warning (demoted to message) VSX1000: No Address and User has been specified in order to establish a connection to a Mac Server, so only the main assembly was compiled for project 'MediumService.iOS'. Connect to a Mac Server and try again to build the full application." />
</Target>
<Target Name="_SayGoodbye">
</Target>
<Target Name="_DetectSdkLocations">
</Target>
<Target Name="_CollectBundleResources">
</Target>
<Target Name="_PackLibraryResources">
</Target>
<Target Name="CopyFilesToMacOutputDirectory">
</Target>
</Project>
We do nothing special to change the warning behavior in VSTS/TFS build comparing with local build through visual studio.
As far as I known, suppressing warnings with MSB prefix is still not possible. Refer to: Supress/Disable/Solve Visual Studio Build Warning
You could give a try with /property:WarningLevel=0through MSBuild argument. Not sure if it will work with this kind of warning above. If not, afraid there is no way to bypass it.
You should use /nowarn:VSX1000 per msbuild documentation
I'd like to add a small variation of Tore Østergaard's answer in case you converted your CSPROJ to an SDK-style project (which iOS projects at this time are usually not, but you can make it work).
In an SDK-style project the "system" targets and props are imported via an SDK attribute at the top of the CSPROJ, like this:
<Project Sdk="MSBuild.Sdk.Extras">
... various project settings ...
</Project>
But if you try to use Tore Østergaard's answer, it won't work, because that answer's target overrides will be themselves overwritten by the SDK's targets (which are always imported last).
The workaround is to manually import the SDK targets and props so that you can control their order:
<Project>
<!--
The SDK is imported manually so that certain targets can be overridden (see bottom of file).
Otherwise we could use Project Sdk="MSBuild.Sdk.Extras"
-->
<Import Project="Sdk.props" Sdk="MSBuild.Sdk.Extras" />
... various project settings ...
<!-- See comment at top of file about manually importing SDK -->
<Import Project="Sdk.targets" Sdk="MSBuild.Sdk.Extras" />
<!--
These targets must be imported last so that they override the SDK-provided targets.
These override the Mac build agent command because they are not needed on CI.
-->
<Import Project="AvoidMacBuildWarning.targets" Condition=" '$(SkipMacBuild)' == 'true' " />
</Project>
Note: I also changed the condition to be a specific condition SkipMacBuild, but you can use whatever condition you want that makes sense for your build.
I also had to add an additional "empty target" to AvoidMacBuildWarning.targets to ensure they were also quieted. My full AvoidMacBuildWarning.targets looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Inspired by https://stackoverflow.com/a/47182083 from Tore Østergaard -->
<Target Name="_SayHello">
<Message Text="INFO: This would have been MSBuild warning VSX1000, but it has been ignored by importing this targets file." />
</Target>
<Target Name="_SayGoodbye">
</Target>
<Target Name="_DetectSdkLocations">
</Target>
<Target Name="_CollectBundleResources">
</Target>
<Target Name="_PackLibraryResources">
</Target>
<Target Name="CopyFilesToMacOutputDirectory">
</Target>
<Target Name="_VerifyBuildSignature">
</Target>
<Target Name="_VerifyXcodeVersion">
</Target>
</Project>
Related
I'm trying to run this jar to serve my JavaScript code for my node application every time the user runs the project. I've tried editing the .njsproj file to include my custom build task (see below) but I think I've reached the opinion that the .njsproj files do not work in the same way as other visual studio project files.
Is there anyway I can automate my task?
Can't find anything helpful or that works on Google. Don't mind what technology is used to do the job as long as it can be automated.
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Plovr>plovr\plovr.jar</Plovr>
<PlovrConfig>plovr\plovr-config-debug.js</PlovrConfig>
</PropertyGroup>
<Target Name="BeforeBuild">
<Message Text="Plovr: $(Plovr)"/>
<Message Text="PlovrConfig: $(PlovrConfig)"/>
<Exec Command=""C:\Program Files (x86)\Java\jre7\bin\java.exe" -jar $(Plovr) build $(PlovrConfig)"/>
</Target>
</Project>
Our solution contains ~50 projects. They all import a custom .target file that sets the OutDir variable so that all projects build to a common Binaries folder.
Problem is: MSBuild does not check the OutDir folder for the .dlls but keeps looking inside the OutputPath folder (e.g. bin\Debug). As the OutputPath folder is empty it states that each project is not up-to-date and forces a rebuild. This is not an issue on our TFS build agents but it drastically increases the time between hitting F5 and the application starting on our development machines. Debugging becomes quite a pain.
From the Binaries folder we copy the .dlls to our applications folder structure which we use for generating setups etc. Thus simply dropping the use of OutDir in favor of various OutputPaths is not an option.
Is there any way to tell MSBuild to also check the OutDir folder when looking for existing .dlls?
Following import in csproj files works for me in VS 2015. I added comments about which settings make it fail:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<!-- to distinguish by $(Platform) does not work, a rebuild is triggered since the up-to-date check fails -->
<!-- if IntermediateOutputPath is not set here at all, it does not work either, i.e. it always rebuilds -->
<IntermediateOutputPath>$(SolutionDir)obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<DisableFastUpToDateCheck>false</DisableFastUpToDateCheck>
</PropertyGroup>
<PropertyGroup Condition=" '$(OutputType)' == 'Library' ">
<!-- To distinguish by \lib\ does not work, a rebuild is triggered since the up-to-date check fails -->
<!-- <OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\lib\</OutputPath> -->
<OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)</OutputPath>
<OutDir>$(OutputPath)</OutDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(OutputType)' == 'Exe' ">
<OutputPath>$(SolutionDir)bin\$(Configuration)\$(Platform)\</OutputPath>
<OutDir>$(OutputPath)</OutDir>
</PropertyGroup>
</Project>
The file is included in csproj files just before Import Microsoft.CSharp.targets:
.csproj file:
<!-- position of include is important, OutputType of project must be defined already -->
<Import Project="$(SolutionDir)ComponentBuild.props" Condition="Exists('$(SolutionDir)ComponentBuild.props')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
Also see my own SO question about it:
MSBuild, OutputPath to a lib directory is not honoured
I've added a 'BeforeClean' and an 'AfterClean' target to my .csproj file, originally designed to delete some build artifacts in locations outside the normal build path.
When I did a "clean" on the project, I could tell that the files weren't getting deleted; so I dumbed down the action to just spit a message out. Like the delete command, the message command isn't getting invoked (I'm expecting to see the message in the 'Output' window).
The only relevant advice I could find on the web was to make sure that you do your target definitions after you import the Microsoft.CSharp.targets file. I'm including the clip of my .csproj file with enough detail to show where my target defs are vis-a-vis the import.
As far as I can tell, I'm doing everything right; why would my targets not get invoked?
Thanks in advance.
[Update and FYI: I was able to get the Target to fire when changing Importance from 'normal' to 'high.']
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<Target Name="BeforeClean">
<Message Text="Hello Clean World!" Importance="normal" ContinueOnError="true"/>
</Target>
<Target Name="AfterClean">
<Message Text="Goodbye Clean World!" Importance="normal" ContinueOnError="true"/>
</Target>
</Project>
It actually is getting invoked, you just can't see it. Run msbuild.exe with /verbosity:normal. Or change the IDE setting: Tools + Options, Projects and Solutions, Build and Run. Or change the Importance attribute to high.
<Target Name="AfterClean"> is ignored in dotnet core with <Project Sdk="Microsoft.NET.Sdk">, and the problem isn't the verbosity. Instead, the AfterTargets="Clean" approach works:
<Target Name="PrintGoodbye" AfterTargets="Clean">
<Message Text="Goodbye Clean World!" Importance="normal" ContinueOnError="true"/>
</Target>
run like:
$ dotnet clean
MSBuild version 17.3.2+561848881 for .NET
Build started 12/9/2022 9:05:04 AM.
1>Project "C:\code\dotNetBytes\Tests\Tests.csproj" on node 1 (Clean target(s)).
1>PrintGoodbye:
Goodbye Clean World!
1>Done Building Project "C:\code\dotNetBytes\Tests\Tests.csproj" (Clean target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.82
Basically, I am trying to implement some pre and post build events for an entire solution instead of just standalone projects. I have seen this question around here before, but not addressing the same problem. I have created two .targets files by the name of after.TestSolution.sln.targets and before.TestSolution.sln.targets. Within each:
before
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CreateFile" BeforeTargets="Build">
<Message Text="Creating a file" Importance="high" />
<Exec Command="C:\users\me\Desktop\CreateFiles.bat" />
</Target>
</Project>
after
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyFile" AfterTargets="Build">
<Message Text="Copying a File" Importance="high" />
<Exec Command="C:\users\me\Desktop\CopyFiles.bat" />
</Target>
</Project>
These are just simple test batches to see if the events work. I then build the solution through MSBuild from command line: this works fully. MSBuild executes the code within the "before" before the solution builds and the same for the "after" afterwards. HOWEVER, the problem is when I go to build the solution from VS, the batches are never run. So, I am not sure as to why this is. I am fairly new to MSBuild tasks.
This is a known VS feature/bug. As mentioned, VS does not build in the same way as msbuild. Msbuild on the commandline generates an msbuild file from the solution (if you set the MSBUILDEMITSOLUTION environment variable to 1, you'll see a .metaproj file generated for your solution in which the before/after targets are imported). It's my understanding VS does not do that but instead invokes msbuild programatically with no extension points for the solution.
I'm hoping to stop including the generated JavaScript files in TFS source control, but I haven't managed to get the compiler to run on a build.
I've followed this chap's example and edited the project file to give me:
<ItemGroup>
<TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>
<Target Name="BeforeBuild">
<Message Text="Before Build" Importance="high" />
<CallTarget Targets="TypeScriptBuild"/>
</Target>
<Target Name="TypeScriptBuild" Inputs="#(TypeScriptCompile)" Outputs="%(Identity).Dummy" Condition="'$(CompileTypeScript)'=='true'">
<Message Text="Building typescript file - #(TypeScriptCompile)" Importance="high" />
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\tsc" -target ES3 "#(TypeScriptCompile)"" />
</Target>
I've changed the file location where the tsc executable is and removed the TypeScript version information, but it isn't doing anything for me. I'm a complete newbie at this build stuff so would appreciate any help, or tips on how to debug it.
Edit 1
Removed
<ItemGroup>
<TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>
as it was redundant - this is added individually for every TypeScript file in the project.
The only warnings I'm getting are about inconclusive unit tests. I assumed that <Message Text="Before Build" Importance="high" /> would produce some kind of log message but I can't see it anywhere.
Edit 2
Got it working locally within Visual Studio by putting
<Target Name="BeforeBuild">
<Message Text="Compiling typescript...">
</Message>
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\tsc" -target ES3 #(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
at the end of the .csproj file. For some reason this doesn't work when TFS is building it. If I change the TypeScript compiler file location to something nonsensical it complains, but when it's correct there are no JavaScript files produced.
You really shouldn't have to do any of this. Make sure this line is in your csproj, before the </project>
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
Then install TypeScript on the build machine. Also you need to make sure the Build Action of the .ts files is set to TypeScriptCompile. At this point, TypeScript will compile your .ts files and generate the js files. You won't (and shouldn't) check the .js files into your code repository.
Unit Tests
You really want your unit tests building with the rest of your code. Even more, you can run these unit tests at build time and use them to fail the build if any of those tests fail!
Check out this post on msdn and this post on codeplex to help get you started. It will involve using Chutzpah. Also, be aware that the way your .js bundling / delivery may be different when using Chutzpah, since Chutzpah will have to build that bundle for you and I'm not sure how your actual site is doing it.