Thursday, March 27, 2014

Sharing library project across solutions and NuGet


UPDATE:
Latest NuGet doesn't rely on 'Enable NuGet Package Restore’ feature: http://docs.nuget.org/docs/reference/package-restore
So instead I recommend checking this: http://www.damirscorner.com/CategoryView,category,DevelopmentNuGet.aspx

I have several applications using one library where communication to the backend API is implemented.
Here’s how the folder hierarchy for projects looks like
Api
  Api.csproj
  Api.sln
App1
  App1.csproj
  App1.sln
App2
  App2.csproj
  App2.sln
Each app solution (App1, App2) has Api.csproj added.
The main reason why Api project is added to app solutions is we want to debug and step into the code of Api library easily.
But this might not be a good idea because each app can depend on a specific version of the Api library. If something needs to be changed in the Api which affects all applications, all applications would need to be updated and sometimes the impact of the changes in the app is complex.
For this reason, we might want to have each app depending on a specific version of the Api, so instead of adding the project as reference, we could add the compiled library as reference.
We can solve the problem to step into the library source code by also having library.pdb files along with the .dll.
More info:
http://www.xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions
http://blog.stangroome.com/2013/11/26/nuget-reference-paths-for-projects-in-multiple-solutions/ (see comment)
http://blog.stangroome.com/2013/12/05/visual-studio-solutions-projects-and-shared-code/
http://www.xavierdecoster.com/post/2011/11/16/why-everyone-should-be-using-a-symbol-server
http://www.edsquared.com/2011/02/12/Source+Server+And+Symbol+Server+Support+In+TFS+2010.aspx

However, suppose we still want to add the library as source code to app solutions.
There’s a problem with NuGet that it’s creating ‘packages’ folder per solution.
http://stackoverflow.com/questions/18376313/setting-up-a-common-nuget-packages-folder-for-all-solutions-when-some-projects-a
Here’s how to do it:
  1. delete existing ‘package’ folder in each solution folder
  2. for each solution, right-click on the solution file in the solution explorer > ‘Enable NuGet Package Restore’
  3. this will create a .nuget folder. open the NuGet.config
  4. add the following under <configuration> node:
    <config>
      <add key="repositoryPath" value="../../packages" />
    </config> (NOTE: if you're using Xamarin, you MUST use forward slashes, otherwise on Mac you will get a folder with the name '..\..\packages' !)
    it instructs NuGet to use ‘packages’ folder located at the same level with Api and apps solution folders.
    note that this path is relative to the location of NuGet.config file
  5. go to each .csproj and make sure all paths which reference ‘packages’ folder are set to “..\..\packages’
  6. delete each ‘.suo’ file in solution folders
  7. reopen Visual Studio
  8. open each app solution and build it.
    for the first solution being built, NuGet brings the packages in the new ‘packages’ folder.
    all other solutions will reference the already downloaded packages

References:
http://forums.xamarin.com/discussion/17783/add-manage-nuget-packages-per-solution
http://lastexitcode.com/blog/2014/08/10/NuGetSupportInXamarinStudio5-2/

Friday, March 14, 2014

Install GooglePlay in emulator

 

I am using the info from http://stackoverflow.com/questions/11154222/google-play-on-android-4-0-emulator#answer-11213598

1. Go to http://wiki.rootzwiki.com/Google_Apps#Universal_Packages_2 and get the latest .zip compatible with your target device.
    Note the “Not compatible with x.x.x!” remarks

2. Start your emulator:

cd %LocalAppData%\Android\android-sdk\tools
emulator -avd VM_NAME_HERE -partition-size 500 -no-audio -no-boot-anim

Then use the following commands:

cd %LocalAppData%\Android\android-sdk\platform-tools

# Remount in rw mode
adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system

# Allow writing to app directory on system partition
adb shell chmod 777 /system/app

# Install following apk
adb push GoogleLoginService.apk /system/app/.
adb push GoogleServicesFramework.apk /system/app/.
adb push Phonesky.apk /system/app/. # Vending.apk in older versions
adb shell rm /system/app/SdkSetup*
 

Saturday, January 25, 2014

Type-safe ViewModel to ViewModel navigation in MvvmCross


In MvvmCross you can navigate between view-model's as described in the Wiki:
https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation

It's good however to use a simple type-safety mechanism.
Suppose we have a ProductViewModel which expects two arguments for initialization:

public class ProductViewModel : MvxViewModel
{
     public void Init(int productId, int clientId)
     {
          ....
     }
}

With a type-safe mechanism, instead of writing:

ShowViewModel<ProductViewModel>(new { productId = pid, clientId = cid });

we can write:

NavigationHelper.ShowProduct(pid, cid);

where NavigationHelper is a simple utility class:

using Cirrious.CrossCore;
using Cirrious.MvvmCross.ViewModels;
using Cirrious.MvvmCross.Views;
using MyApp.Core.ViewModels;
using Cirrious.MvvmCross.Platform;

namespace MyApp.Core.Common
{
    public static class NavigationHelper
    {
        public static void ShowProduct(int productId, int clientId)
        {
            ShowViewModel<ProductViewModel>(new { productId = productId, clientId = clientId });
        }

        static void ShowViewModel<T>(object parameter) where T : IMvxViewModel
        {
            var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
            var request = MvxViewModelRequest.GetDefaultRequest(typeof(T));
            request.ParameterValues = ((object)parameter).ToSimplePropertyDictionary();
            viewDispatcher.ShowViewModel(request);
        }
    }
}

using Cirrious.MvvmCross.Platform; namespace statement is important because it contains the ToSimplePropertyDictionary() extension method implemented by MvvmCross.

Furthermore, instead of using the NavigationHelper class, we can move the ShowViewModel method to a ViewModelBase class:

public class ViewModelBase : MvxViewModel
{
       protected static void ShowViewModel<T>(dynamic parameter) where T : IMvxViewModel        
       {            
           var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();            
           var request = MvxViewModelRequest.GetDefaultRequest(typeof(T));            
           request.ParameterValues = ((object)parameter).ToSimplePropertyDictionary();            
           viewDispatcher.ShowViewModel(request);        
       }
}

public class ProductViewModel : ViewModelBase
{
    public static Show(int productId, int clientId)
    {
        ShowViewModel<ProductViewModel>(new { productId = productId, clientId = clientId });
    }

    public void Init(int productId, int clientId)
    {
        ...
    }
}

and we can now write:

ProductViewModel.Show(pid, cid);

Having the Show method near the Init method in the ViewModel class, makes it a bit more easier to maintain the parameters.

Saturday, January 18, 2014

ASP.NET errors

 

#1. There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined

Check .NET Framework version for app pool.

Projects developed in (2.0,3.0,3.5) should run under an Application Pool with .NET FRAMEWORK VERSION v2.0.50727 

Projects developed in 4.0 should run under an Application Pool with .NET FRAMEWORK VERSION v4.0.30319

#2. Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Make sure that "Enable 32 - Bit Applications" is set to false or true for the app pool, depending on System.Data.SQLite.dll

System.Data.SQLite.dll is a mixed assembly, i.e. it contains both managed code and native code. Therefore a particular System.Data.SQLite.dll is either x86 or x64, but never both.

#3. HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Requested URL
   http://localdev.site.com/Webservices/UserProviderService.svc

You need to run this: http://enginecore.blogspot.ro/2013/06/svc-handling-in-iis.html

Thursday, January 16, 2014

Invalid markup in XAML in Visual Studio 2013


If you get this error in designer when there’s clearly no error in your XAML:
- close all files open in Visual Studio
- close Visual Studio
- delete the .suo file near the .sln
- delete bin and obj folders

if still doesn't work you can try to delete all directories from:
%LocalAppData%\Microsoft\VisualStudio\12.0\Designer\ShadowCache

More info:
http://stackoverflow.com/questions/12871358/visual-studio-2012-xaml-designer-invalid-markup
http://forums.xamarin.com/discussion/10284/xamarin-new-pcls-w8-wp8-net45-xamarin-ios-xamarin-droid-plus-new-microsoft-bcl-terribly-broken

Monday, January 13, 2014

Installing Windows 8 and customization

1. Use Windows 7 USB/DVD download tool to create a Windows bootable USB drive

2. If you want to create a Windows x64 bootable image, you need to run the Windows 7 USB/DVD download tool from a x64 Windows computer.

3. During the Windows 8 installation if you encounter error while installing \ copying files, and it’s at the same point (same percent), then the USB image is corrupted.

4. If doing Android dev. with Intel x86 Emulator Accelerator (HAXM), you must disable Hyper V in Windows.
disable: bcdedit /set hypervisorlaunchtype off
re-enable (restart): bcdedit /set hypervisorlaunchtype auto
5. For Samsung 840 Pro SSD: Install Samsung Magician
     http://www.samsung.com/global/business/semiconductor/samsungssd/downloads.html
It will start on each Windows start but it’s annoying it shows UAC. One solution is to remove it from startup

C:\users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
6. There are a number of SSD optimizations to be done
http://www.thessdreview.com/ssd-guides/optimization-guides/the-ssd-optimization-guide-ultimate-windows-8-edition/

7. Disable Windows Narrator. it’s annoying it starts anytime Windows Key + Enter are pressed.
http://enginecore.blogspot.ro/2013/09/disable-windows-narator.html
8. Make Word to minimize to tray: right click on tray icon and choose “Hide when minimized
9. Automatically user login
1. run netplwiz 
2. uncheck the “Users must enter a user name and password to use this computer”, click Apply
3. enter username and password
http://www.howtogeek.com/112919/how-to-make-your-windows-8-computer-logon-automatically/
10. Force Visual Studio always run as admin
http://stackoverflow.com/questions/12257110/can-you-force-visual-studio-to-always-run-as-an-administrator-in-windows-8

In Windows 8, you have to right-click devenv.exe and select "Troubleshoot compatibility".
  1. select "Troubleshoot program"
  2. check "The program requires additional permissions"
  3. click "Next", click "Test the program..."
  4. wait for the program to launch
  5. click "Next"
  6. select "Yes, save these settings for this program"
  7. click "Close"
11. On Windows 8, make sure you get the latest Intel x86 Emulator Accelerator (HAXM), At this moment, the one from Android SDK manager is buggy on Windows 8. 
http://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager/