How to properly import WixBalExtension in wixproj file? - wix

I am trying to import the WixBalExtension.dll. I confirmed that the path is correct, but I'm running into the following error:
The extension 'Wix\WixBalExtension.dll' could not be loaded because of the following reason: Could not load file or assembly 'WixBalExtension, Version=3.0.0.0, Cul
ture=neutral, PublicKeyToken=ce35f76fcda82bad' or one of its dependencies. Strong name validation failed. (Excep
tion from HRESULT: 0x8013141A)
This is what my extensions look like in the wixproj file:
<ItemGroup>
<Compile Include="Project.wxs" />
<WixExtension Include="$(Wix_Dir)\WixNetFxExtension.dll" />
<WixExtension Include="$(Wix_Dir)\WixUIExtension.dll" />
<WixExtension Include="$(Wix_Dir)\WixUtilExtension.dll" />
<WixExtension Include="$(Wix_Dir)\WixIIsExtension.dll" />
<WixExtension Include="$(Wix_Dir)\WixDependencyExtension.dll" />
<WixExtension Include="$(Wix_Dir)\WixBalExtension.dll"/>
</ItemGroup>
Is there something that I'm missing? The error isn't clear on whether it's a dependency missing or something else. Thanks.

Strong name validation failed. indicates you have a corrupt file. Try checking the digital signature in Explorer.

Related

MSBuild cannot find a reference - ReactJs.NET

After upgrading Newtonsoft.Json to version 9.0.0 and ReactJS.Net packages to 2.5.0, the TransformBabel.proj stopped working:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformBabel">
<!-- ReactJS.NET - Transpile JavaScript via Babel -->
<UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformBabel" />
<Target Name="TransformBabel">
<TransformBabel SourceDir="$(MSBuildProjectDirectory)" />
</Target>
</Project>
Returning the following:
TransformBabel.proj(6, 3): error MSB4018: The "TransformBabel" task failed unexpectedly.
[Exec] TransformBabel.proj(6, 3): error MSB4018: React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.IReactSiteConfiguration ---> System.TypeInitializationException: The type initializer for 'React.ReactSiteConfiguration' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
It seems that it cannot load the Newtonsoft 6.0.0.0 version. The web.config has an assembly redirection:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
But I am not sure that, as it is starting a new msbuild process, if it is being ignored. I would like to hint msbuild the location of the assembly, but no success until now.
A bit late to the party here, but hopefully my experience will help to anyone else having the same problem.
I have recently experienced the same issue with React.MSBuild 3.1.0. It seems that it has hardcoded a specific version as I have updated my Newtonsoft.Json to the latest (10.0.3) using NuGet and set redirection correctly, but the build kept failing on the same error as you have mentioned.
What I did is simply uninstall all the React packages (MSBuild and Core) and also Newtonsoft.Json (using -force as there were other dependencies) and then let NuGet install the React.MSBuild again. It has installed it with all dependencies what resulted in obtaining Newtonsoft.Json 9.0.1.
Not sure why do they restrict Newtonsoft.Json library to a specific version, but it is more a question to React developers. Unless you need a latest (or other specific version of it), this should fix the problem.
I know this is an old post...but here is my workaround:
I put Newtonsoft.Json.dll v6.0.0.0 into Tools directory relative to the project directory and let msbuild copy it to $(OutputPath) to satisfy TransformBabel task condition.
My TransformBabel.proj looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformBabel">
<!-- ReactJS.NET - Transpile JavaScript via Babel -->
<UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformBabel" />
<Target Name="TransformBabel">
<Copy SourceFiles="$(MSBuildProjectDirectory)\Tools\Newtonsoft.Json.dll" DestinationFolder="$(OutputPath)" />
<TransformBabel SourceDir="$(MSBuildProjectDirectory)" />
</Target>
</Project>
After this TransformBabel task is finished, then let msbuild overwrite Newtonsoft.Json.dll v6.0.0.0 in $(OutputPath) with whatever Newtonsoft.Json.dll version my project is actually using, ex: v8.0.3.
So, in the main project .csproj, I have something like this:
<ItemGroup>
...
<Reference Include="React.MSBuild, Version=2.3.0.0, Culture=neutral, PublicKeyToken=9aed67b161f7db78, processorArchitecture=MSIL">
<HintPath>Tools\React.MSBuild.dll</HintPath>
<Private>True</Private>
</Reference>
...
</ItemGroup>
...
<ItemGroup>
...
<Content Include="Tools\Newtonsoft.Json.dll" />
<Content Include="Tools\React.MSBuild.dll" />
...
</ItemGroup>
...
<Target Name="TransformBabel" AfterTargets="Build">
<Exec Command=""$(msbuildtoolspath)\msbuild.exe" $(ProjectDirectory)TransformBabel.proj /p:OutputPath=$(OutputPath) /nr:false" />
</Target>
<Target Name="AfterTransformBabel" AfterTargets="TransformBabel">
<Copy SourceFiles="..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll" DestinationFolder="$(OutputPath)" />
</Target>
Replace the path Newtonsoft.Json.8.0.3 inside AfterTransformBabel task to your need.

MSBuild inline task reference is escaping parenthesis, sometimes

I am writing an inline task for MSBuild. It requires a reference to System.ServiceProcess.dll.
The task works great if I hard-code the path to the System.ServiceProcess.dll file, like this:
<UsingTask
TaskName="MyTask"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<Task>
<Reference Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ServiceProcess.dll" />
<Code Type="Fragment" Language="cs">...working fine...</Code>
</Task>
</UsingTask>
However, I would rather not hard-code that path.
If I just use <Reference Include="System.ServiceProcess.dll" />, I get an error: MSB3755: Could not find reference "System.ServiceProcess.dll", so I think I have to use the full path here.
The $(FrameworkPathOverride) property contains the correct path already, so I tried to use that:
<Reference Include="$(FrameworkPathOverride)\System.ServiceProcess.dll" />
But that gives me an error:
C:\path\to\project.csproj(93,3): error MSB3754: The reference assembly "C:\Program Files %28x86%29\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ServiceProcess.dll" is invalid. "The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)"[C:\path\to\project.csproj]
Notice how it escaped (x86) into %28x86%29.
Notably, it seems to do this only for $(FrameworkPathOverride). If I define my own property and use it instead, it works just fine, unless that property also references $(FrameworkPathOverride). In other words, this works (but still has me hard-coding the path):
<PropertyGroup>
<MyPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5</MyPath>
</PropertyGroup>
// (later, inside <Task />)
<References Include="$(MyPath)\System.ServiceProcess.dll" />
However, this fails with the same error that reports searching a path for %28x86%29:
<PropertyGroup>
<MyPath>$(FrameworkPathOverride)</MyPath>
</PropertyGroup>
Just for kicks, I also tried this variation, which also fails with the same error:
<PropertyGroup>
<MyPath>$([System.Convert]::ToString("$(FrameworkPathOverride)"))</MyPath>
</PropertyGroup>
Also, in all cases, the output of <Message Text="$(FrameworkPathOverride)" /> and <Message Test="$(MyPath)" /> are identical. The <Message /> task is not escaping the parenthesis inside $(FrameworkPathOverride), but the <Reference Include="..." /> is. Hmm.
Why does (x86) become %28x86%29 inside <Reference /> but not inside <Message />?
Why does it happen for $(FrameworkPathOverride) and not for $(MyPath)?
Why does it start happening to $(MyPath) if it references $(FrameworkPathOverride)?
How can I avoid hard-coding this path?
Similar to your last attempt, have you tried the following using the "Unescape" MSBuild Property Function?
<PropertyGroup>
<MyPath>$([MSBuild]::Unescape("$(FrameworkPathOverride)"))</MyPath>
</PropertyGroup>
It seems to be a known issue titled "MSBuild 4.0 UsingTask cannot have a path with parentheses": http://connect.microsoft.com/VisualStudio/feedback/details/532677/msbuild-4-0-usingtask-cannot-have-a-path-with-parentheses
Unfortunately, I have not had the opportunity to test this.

AjaxMin task has been declared or used incorrectly, or failed during construction

I'm trying to add Microsoft's AjaxMin to VS2012 project and I'm not really sure what I'm doing. I think I'm missing something obvious.
I copied the code from the tutorial here (http://ajaxmin.codeplex.com/wikipage?title=AjaxMinTask)
And I've tried adding the reference to my project so my code looks like this:
<UsingTask TaskName="AjaxMin" AssemblyFile="$(MSBuildProjectDirectory)\Build\AjaxMinTask.dll" />
<Target Name="AfterBuild" >
<ItemGroup>
<JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
</ItemGroup>
<ItemGroup>
<CSS Include="**\*.css" Exclude="**\*.min.css" />
</ItemGroup>
<AjaxMin JsSourceFiles="#(JS)" JsSourceExtensionPattern="\.js$" JsTargetExtension=".min.js" CssSourceFiles="#(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />
</Target>
This is at the bottom of my .csproj file where there was already a commented out AfterBuild section. I get errors saying JS, CSS, AjaxMin are invalid child elements. When I try to build the project I get an error, I'm not sure what I am missing. I created a folder in the project called Build and added the AjaxMinTask.dll. I don't know if there's any additional thing i need to do to make sure it is referenced properly.
I've also tried using the Import node instead of the UsingTask
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\AjaxMin.tasks" />
And I think AjaxMin is installed correctly because I can run it from command line.
In your .csproj, the end of the document (I've included the last closing element ) should look something like this:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\MicrosoftAjax\AjaxMin.tasks" />
<Target Name="AfterBuild" AfterTargets="CopyAllFilesToSingleFolderForPackage" Condition="'$(Configuration)'=='Release'">
<ItemGroup>
<JS Include="scripts\*.js" Exclude="scripts\*.min.js;" />
</ItemGroup>
<ItemGroup>
<CSS Include="css\main.css" />
</ItemGroup>
<AjaxMin Switches="-global:jQuery,$" JsSourceFiles="#(JS)" JsCombinedFileName="scripts\combined.min.js" CssSourceFiles="#(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />
</Target>
</Project>
As I am using Windows 7 64-bit, you will see the path of Import... includes (MSBuildExtensionsPath32). If you are using Windows 32-bit, then you do not need the 32 at the end. Other then that, your code should work.
Disregard the JS, CSS, AjaxMin childelements error. But you should not get a built error. If you could post your built error, it would be useful.
Also, the code above combines multiple JS files, just added for fun.

NANT CSC Build Failure: References Missing?

I have the following NANT CSC target for building winexe:
<csc target="winexe" output="${Deploy.dir}\VMIS.exe" debug="${debug}">
<sources>
<include name="${App.dir}\**\*.cs" />
<include name="${Build.dir}\AssemblyInfo.cs" />
<exclude name="${App.dir}\**\AssemblyInfo.cs" />
</sources>
<references refid="Lib.fileset">
</references>
...
</csc>
The following is the failure message:
D:\..\myClass.cs(9,17): error CS0234: The type or namespace name 'Reporting'
does not exist in the namespace 'Microsoft' (are you missing an assembly
reference?)
In myClass.cs, I have this using reference:
using Microsoft.ReportViewer.WinForms;
There is no problem to build my app in VS, but I could not build from NANT. I think that I may miss reference to Microsoft.ReportViewer.WinForms.dll in NANT build. Not sure how I can include this dll in my bin for NANT?
I have tried to modify csc target's references:
<csc ...>
...
<references refid="Lib.fileset">
<include name="Microsoft.ReportViewer.Common.dll" />
<include name="Microsoft.ReportViewer.WinForms.dll" />
</references>
...
</csc>
Still not working. Should I use COPY target to copy all the dll files from bin to $(build.dir)?
Updates: I found that those Microsoft.ReportViewer.xx.dll files in project references are not copy to local. How can I simulate copy to local in NANT for those two dll files? I guess that may resolve the issue since NANT is a build app in console and does not have knowledge about references in global cache.
NAnt is configured with the default set of DLLs for the .NET framework, and knows where those DLLs reside (e.g. C:\Windows\Microsoft.NET\Framework64\v4.0.30319). When you include non-framework assemblies, whether they are yours or a 3rd party, you can include them, but use the full path of the DLL:
<include name="C:\Common\ThirdParty.dll" />
You can also use variables:
<property name="common.directory" value="C:\Common" />
...
<csc ...>
...
<references>
<inclde name="${common.directory}\ThirdParty.dll" />
</references>
</csc>
Recommended:
Use MSBuild in your NAnt script(s) to build your application.
FYI: Visual Studio uses MSBuild to compile and build your solution and projects.
<!-- Verify the right target framework -->
<property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />
<target name="Build">
<exec program="${MSBuildPath}">
<arg line='"${SolutionFile}"' />
<arg value="/target:Rebuild" />
<arg value="/verbosity:normal" />
<arg value="/nologo" />
</exec>
</target>
Possibility:
Copy references/files locally (i.e. using copy task). Or similarly use full paths in the include name.
Not recommended:
Use NAnt's "solution" task, or NAntContrib's "msbuild" task.
This would simplify the msbuild call but would tie you into older versions of msbuild/VS solution/project files. Newer VS solution/project files would not be supported readily.
Hope it helps.

CSC task in Msbuild aborts with namespace errors

I have attempted the following:
<!-- Specify the inputs by type and file name -->
<ItemGroup>
<CSFile Include = "$(MSBuildProjectDirectory)\..\Mine.cs"/>
</ItemGroup>
<Target Name = "Compile">
<!-- Run the Visual C# compilation using input files of type CSFile -->
<Csc Sources="#(CSFile)" />
<!-- Log the file name of the output file -->
<Message Text="The output file is done"/>
</Target>
This does not work as all the namespaces used in the project throw errors. Does anyone know how I can explicitly get the assemblies to pick up from the solution file, as the paths are ok and if loaded in Visual Studio all is fine. I need to script this and the above is not working. Is there an obvious mishap?
Appreciate the inpuT :-)
I have realised that this is not going to work as the file I have has several external dependancies. Hence I would need to use the devenv.exe. Problem is that I get the follwing:
What I get is that the command exits with Code 1? I want to get the project to build all the dependant dlls that it requires without having to open visual studio.
Any ideas?
Thnxes :-)
try this (add you own dlls references)
<ItemGroup>
<CSFile Include = "$(MSBuildProjectDirectory)\..\Mine.cs"/>
<Reference Include="System.dll"/>
<Reference Include="System.Data.dll"/>
<Reference Include="System.Drawing.dll"/>
<Reference Include="System.Windows.Forms.dll"/>
<Reference Include="System.XML.dll"/>
</ItemGroup>
<Target Name = "Compile">
<!-- Run the Visual C# compilation using input files of type CSFile -->
<Csc Sources="#(CSFile)"
References="#(Reference)"
OutputAssembly="$(builtdir)\$(MSBuildProjectName).exe"
TargetType="exe" />
/>
<!-- Log the file name of the output file -->
<Message Text="The output file is done"/>
</Target>