How do I sign APPX file for WP81 using MSBuild? - msbuild

I need to sign a LOB/enterprise app (built as APPX) for Windows Phone 8.1 for internal distribution. I tried to use MSBuild SignFile task:
<Target Name="SignAppxPhone" AfterTargets="_CreateAppxPackage">
<SignFile
CertificateThumbprint="$(CertificateThumbprint)"
SigningTarget="$(AppxPackageOutput)"
TargetFrameworkVersion="v4.5" />
</Target>
I am getting the following error:
error MSB3482: An error occurred while signing: Data at the root level is invalid. Line 1, position 1.
What's wrong?

MSBuild SignFile task only supports PE files (*.exe, *.dll) and XML, unfortunately. APPX files or CAB files are not supported. I looked in Reflector at the latest version of Microsoft.Build.Tasks.v12.0.dll -- shipped with Visual Studio 2013 Update 3 RC, built on 6/25/2014. It's been reported to Microsoft 6 years ago.
https://connect.microsoft.com/VisualStudio/feedback/details/347731/msbuild-signfile-task-fails-with-cab-files
A reasonable workaround is to <Exec> signtool.exe directly:
<Target Name="SignAppxPhone" AfterTargets="_CreateAppxPackage">
<Exec Command=""$(SignAppxPackageExeFullPath)" sign /fd SHA256 /sha1 $(CertificateThumbprint) /t http://timestamp.verisign.com/scripts/timstamp.dll "$(AppxPackageOutput)"" />
</Target>

Related

Visual Studio - Could not copy the file "obj\Debug\[file].exe" because it was not found

So, I'm trying to build a project I just installed Visual Studio to build this specific project (it is in vb6 so I needed to use the Visual Basic tools extension because i had Visual Studio 2015 installed). I have no programming knowledge on this area, only web.
And when I try to build it it gives me this error:
------ Build started: Project: Proyecto1, Configuration: Debug x86 ------
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(3812,5):
error MSB3030: Could not copy the file "obj\Debug\Proyecto1.exe"
because it was not found. Done building project "Proyecto1.vb6proj" --
FAILED.
Build FAILED.
Then I click on the error and it send me to that piece of code
<!-- Copy the build product (.dll or .exe). -->
<Copy
SourceFiles="#(IntermediateAssembly)"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
<Output TaskParameter="DestinationFiles" ItemName="MainAssembly"/>
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<Message Importance="High" Text="$(MSBuildProjectName) -> #(MainAssembly->'%(FullPath)')" Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)'!='true'" />
I already saw the existent questions for this problem and the solutions didn't worked for me.
In my case it was like #Hans says it was my Antivirus fault (Avast) I disabled it to test if that was the problem, deleted the bin and debug folders and re-opened the solution and it worked perfectly.
P.D. Remember to add you solution folder to your antivirus exclusions.

MSBuild: ProjectReference Output Path in Wix Projects

I'm trying to get the Output folder of referenced project in my Wix Visual Studio project, using MsBuild task. But it is failing with following error:
C:\Program Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(724,5):
error : The OutputPath property is not set for project
'ConsoleApplicatio n1.csproj'. Please check to make sure that you
have specified a valid combination of Configuration and Platform for
this project. Configuration='Release' Platfo rm='x86'. You may be
seeing this message because you are trying to build a project without
a solution file, and have specified a non-default Configuration or
Plat form that doesn't exist for this project.
[C:\Users\fwaheed\Documents\Visual Studio
2015\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cspro
j]
Following is the Target calling MsBuild task.
<Target Name="AfterBuild">
<MSBuild
Projects="#(ProjectReference)"
Targets="GetTargetPath"
BuildInParallel="false"
Condition="'%(Name)'=='ConsoleApplication1'" >
<Output TaskParameter="TargetOutputs" ItemName="DependentAssemblies" />
</MSBuild>
</Target>
Please note that same target worked perfectly if it is CSharp project, but failing in Wix project.
Can someone guide how to get ReferencedProjects output dirs in Wix Projects?
Thanks
You can try to see how Wix does it for passing the reference values to candle on build. They're in the wix2010.targets or wix200x.targets file. Unfortunately I don't have the time to really dig into this stuff but the properties these tasks set should still exist to be used in your AfterBuild target.
Just search for "ResolveReferences" in one of those targets files.
You can also just try setting
<OutputPath>somepathhere</OutputPath>
in your csproj file since msbuild is complaining that the property isn't set.

Visual Studio 2015/Windows 10 SDK SignTool.exe bug?

I have a project that I'm upgrading to Visual Studio 2015 but it's still targeting .NET 4.5.1.
Whenever $(WindowsSDKBinPath) is set to the Windows 10 SDK "C:\Program Files (x86)\Windows Kits\10\bin\x86\" the signtool.exe exits with exit code 255 and the output cuts off like the following:
The following certificate was selected:
Issued to: XXXX
Issued by: VeriSign Class 3 Code Signing 2010 CA
Expires: Tue Apr 11 19:59:59 2017
SHA1 hash: XXXX
Done Adding Additional Store
Usually an error would show up right here if there was going to be an error but that's it, it's cuts off right here and exits with exit code 255.
If $(WindowsSDKBinPath) is set to the Windows 8.1 SDK "C:\Program Files (x86)\Windows Kits\8.1\bin\x86\" then everything is fine. SignTool.exe signs the dll without any issues and exits with code 0 like normal.
Can anyone help me figure out how to use the newer signtool or at least know why it's not working? Below is the target I added to my csproj file to get it to sign after building. Thanks.
<Target Name="AuthenticodeProjectSign" AfterTargets="AfterBuild">
<PropertyGroup>
<AuthenticodeTimestampServerUrl>http://timestamp.verisign.com/scripts/timstamp.dll</AuthenticodeTimestampServerUrl>
<TargetAssembly>$(OutDir)$(TargetFileName)</TargetAssembly>
</PropertyGroup>
<Exec Command=""$(WindowsSDKBinPath)signtool.exe" sign /v /sha1 $(AuthenticodeCertificateSHA1) /t $(AuthenticodeTimestampServerUrl) "$(TargetAssembly)"" />
</Target>
signtool # my Machine and on the buildserver is working. On VisualStudio 2015 and Windows 10 Enterprise 64bit, I had to add the ClickOnce Publishing Tools in VisualStudio Setup:
After this you find signtool.exe in
c:\Program Files (x86)\Windows Kits\8.1\bin\x64\
c:\Program Files (x86)\Windows Kits\8.1\bin\x86\
c:\Program Files (x86)\Windows Kits\8.1\bin\arm\
I ran into the same problem where signtool exits with exit code 255 when using :
C:\Program Files (x86)\Windows Kits\10\bin\x86\signtool.exe
But somehow it works fine using :
C:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe

MSBuild output missing javascript files compiled by Typescript

We use MSBuild on our CI server to compile our WebApp, however the build omits the JavaScript files built by TypeScript from the output of the build.
I would expect the output to contain the JavaScript and not the Typescript, however neither are in the output at the expected locations.
How can I include the JavaScript files without having to have them all in my solution? The TypeScript team seems to think this is bad, but I would rather not have duplicates of all the files in my solution either.
The problem was due to using MSBuild instead of the "Publish" on the build server it seems. I added an AfterBuild target to content include all of the JS files to the build output.
<Target Name="AfterBuild">
<ItemGroup>
<Content Include="**\*.js" />
</ItemGroup>
</Target>
Although this is not ideal, it allows the js files not to show in the solution when using visual studio and the files end up in the build output.
I tried many solutions from the web including the <Content Include="**\*.js" />, but nothing worked. I'm using MSBuild on my local dev box and typescript is installed and targets available in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TypeScript.
It turns out my "old" MSBuild runner for web app csproj files is obsolete. I was doing this:
MSBuild.exe my.csproj /Target:ResolveReferences;_CopyWebApplication /property:WebProjectOutputDir=myfolder;OutDir=myfolder\bin;Configuration=Debug
but thanks to this post I need to use UseWPP_CopyWebApplication instead of the legacy _CopyWebApplication:
MSBuild.exe /t:Rebuild "/p:WebProjectOutputDir=myfolder;OutDir=myfolder\bin;Configuration=Debug;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False" my.csproj
Now without any editing of the csproj file, all my TypeScript is included!
TypeScript is probably not installed on your build server. To install it, copy your TypeScript folder from c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\ to the same folder on your build server (where v12 is the version of your Visual Studio).
The Visual Studio version on your build server can be different however. In my situation, the version on my development machine is v12, while the build server uses v11. I found that out by adding the following to the [WebProjectName].csproj file:
<Target Name="PrintVisualStudioInfo">
<Message Text="VisualStudioVersion: '$(VisualStudioVersion)'" Importance="High" />
</Target>
<PropertyGroup>
<CompileDependsOn>
PrintVisualStudioInfo;
$(CompileDependsOn)
</CompileDependsOn>
</PropertyGroup>
Be sure you put it after the last <Import /> element. Now when you look at the output of your build on the build server, you should see 'VisualStudioVersion: xx' somewhere.
Copy the TypeScript folder to the correct version folder on the build server.
Just adding in case it helps people.
We had this issue recently and it was fixed by adding
/p:VisualStudioVersion=12.0 to the BAT file :
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe FullBuild.proj /p:VisualStudioVersion=12.0 /t:createRelease /p:ReleaseNumber=5.22.0

Overriding MSBuildExtensionsPath in the MSBuild task is flaky

This is already cross-posted at MS Connect:
https://connect.microsoft.com/VisualStudio/feedback/details/560451
I am attempting to override the property $(MSBuildExtensionsPath) when building a solution containing a C# web application project via msbuild. I am doing this because a web application csproj file imports the file "$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets". This file is installed by Visual Studio to the standard $(MSBuildExtensionsPath) location (C:\Program Files\MSBuild). I would like to eliminate the dependency on this file being installed on the machine (I would like to keep my build servers as "clean" as possible). In order to do this, I would like to include the Microsoft.WebApplication.targets in source control with my project, and then override $(MSBuildExtensionsPath) so that the csproj will import this included version of Microsoft.WebApplication.targets. This approach allows me to remove the dependency without requiring me to manually modify the web application csproj file.
This scheme works fine when I build my solution file from the command line, supplying the custom value of $(MSBuildExtensionsPath) at the command line to msbuild via the /p flag. However, if I attempt to build the solution using the MSBuild task in a custom msbuild project file (overriding MSBuildExtensionsPath using the "Properties" attribute), it fails because the web app csproj file is attempting to import the Microsoft.WebApplication.targets from the "standard" Microsoft.WebApplication.targets location (C:\Program Files\MSBuild). Notably, if I run msbuild using the "Exec" task in my custom project file, it works. Even more notably, the FIRST time I run the build using the "MSBuild" task AFTER I have run the build using the "EXEC" task (or directly from the command line), the build works.
Has anyone seen behavior like this before? Am I crazy? Is anyone aware of the root cause of this problem, a possible workaround, or whether this is a legitimate bug in MSBuild?
Steps to Reproduce:
1) Create a new empty solution in MSVS 2008 (Fake.sln)
2) Add a new C# web application to the solution (WebApplication1.csproj)
3) Close MSVS
4) Copy the contents of "C:\Program Files\MSBuild\" to a directory called "MSBuildExtensions" in the directory containing your solution.
5) rename the directory "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications" so that WebApplication1.csproj will not be able to import Microsoft.WebApplication.targets from that location.
6) Create a custom MSBuild project file called "TestBuild.proj" in the same directory as the solution. It should have the following content:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildMSBuild">
<PropertyGroup>
<MSBuildExtensionsPath>$(MSBuildProjectDirectory)\MSBuildExtensions\</MSBuildExtensionsPath>
<BuildThis>Fake.sln</BuildThis>
</PropertyGroup>
<Target Name="BuildMSBuild">
<MSBuild Projects="$(BuildThis)" Properties="MSBuildExtensionsPath=$(MSBuildExtensionsPath);" Targets="Clean" />
<MSBuild Projects="$(BuildThis)" Properties="MSBuildExtensionsPath=$(MSBuildExtensionsPath);"/>
</Target>
</Project>
7) execute "msbuild TestBuild.proj" from a MSVS command prompt (note: the build may succeed the first time, but will fail if you run more than once)
Did you try setting the environment variable MSBuildExtensionPath in the CMD prompt and then running your build?
For example:
C:\> SET MSBuildExtensionsPath=C:\My\MSBuild\Extensons
Then on this project file:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Text='MSBuildExtensionsPath="$(MSBuildExtensionsPath)"' />
</Target>
</Project>
you will get the following output:
c:\Users\chuckeng\Desktop\ConsoleApplication1>"C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" my.proj
Microsoft (R) Build Engine Version 3.5.30729.4926
[Microsoft .NET Framework, Version 2.0.50727.4927]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 6/25/2010 1:04:05 PM.
Project "c:\my.proj" on node 0 (default targets).
MSBuildExtensionsPath="C:\My\MSBuild\Extensons"
Done Building Project "c:\my.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.03
This works from v4.0 as well. Although, support is generally better in v4.0 for things like this. And, v4.0 is 100% backward compatible (bugs not withstanding). So, you can build your v3.5 and prior projects with v4.0. Just select ToolsVersion 3.5.
msbuild my.proj /tv:3.5
Hope this helps...
Chuck England
Visual Studio
Program Manager - MSBuild
This is a bug in MSBuild 3.5 but it is fixed in MSBuild 4.
If you can, switch to MSBuild 4 (you still can compile your 3.5 projects), otherwise you'll have to override the property in the project file.
It works fine if you override MSBuildExtensionsPath directly in the web app .csproj file.
<PropertyGroup>
<MSBuildExtensionsPath>C:\Users\madgnome\Desktop\msbuild</MSBuildExtensionsPath>
<!-- It works too with relative path -->
<!--<MSBuildExtensionsPath>..\msbuild</MSBuildExtensionsPath>-->
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Don't know if this might help anyone in the future, but I was able to use the following at the top of my file and it works as I would expect in both 32 and 64 bit build environments.
<PropertyGroup>
<MSBuildExtensionsPath Condition=" '$(MSBuildExtensionsPath64)' != '' ">$(MSBuildExtensionsPath64)</MSBuildExtensionsPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>