# .NET Development

# Blazor



# URL: Passing variables

Add the path

```
@page "/reader/{Id:int}"
```

Bind the parameter

```csharp
[Parameter]
public string Id { get; set; }
```

It should be said that via the easy mix of code between the server and the GUI - this approach to pass variables might not the best way.   
But it could be used to implement an external facing URL, for example.

You'd then assign a variable with the **@onclick** - where the @-sign denotes it will be run on the server.

[![image.png](/uploads/images/gallery/2024-10/scaled-1680-/zAzimage.png)](/uploads/images/gallery/2024-10/zAzimage.png)

It then allows you to write code that renders different HTML.

[![image.png](/uploads/images/gallery/2024-10/scaled-1680-/yYnimage.png)](/uploads/images/gallery/2024-10/yYnimage.png)

# MAUI - IOS Emulator / Building without MAC

It seems nearly impossible to run an Iphone emulator without a Mac or Iphone device.  
You could invest in a Mac / Macbook or reason to get something cheap refurbished for a few builds.

But for my development, [http://www.macincloud.com](http://www.macincloud.com) was sufficient and quite fast to continue my work.  
Just make sure to get the option to SSH - so you can pair your "Mac in the cloud" to your Visual studio.  
  
Use the credentials that come with the subscription.

[![image.png](/uploads/images/gallery/2024-10/scaled-1680-/shRimage.png)](/uploads/images/gallery/2024-10/shRimage.png)

Once it is paired, you then can debug on an Iphone Emulator

[![image.png](/uploads/images/gallery/2024-10/scaled-1680-/pj1image.png)](/uploads/images/gallery/2024-10/pj1image.png)

# MAUI - physical IPhone deployment (without Mac)

In some cases the MacInCloud isn't sufficient: to test BLE devices you do need a physical device, for example.

In that case, you can get a cheap [Iphone SE2020](https://swappie.com/be/model/iphone-se-2020/) or simular - unfortunately you cannot link that phone over RDP (your macincloud) to its USB to deploy via Visual Studio.

1\) You'll have to [install Itunes ](https://support.apple.com/en-us/118290) and get a developer account  
2\) You'll have to activate your developer account (which is 99€ annually)

[![image.png](https://wiki.sophior.com/uploads/images/gallery/2024-10/scaled-1680-/ssKimage.png)](https://wiki.sophior.com/uploads/images/gallery/2024-10/ssKimage.png)

# MAUI - Connect IPhone to debug

According to Microsoft, an Itunes installation on Windows is enough to target the phone.  
  
However, after some days of debugging (and setting up a virtual machine to generate keys instead) - it turns out that it's a functionality that's broken. Either by Apple or Microsoft.

At time of writing (November 2024) - it hasn't been resolved.

https://developercommunity.visualstudio.com/t/Cannot-add-Apple-Account-VS-2002-Enter/10773193

[![image.png](https://wiki.sophior.com/uploads/images/gallery/2024-10/scaled-1680-/0climage.png)](https://wiki.sophior.com/uploads/images/gallery/2024-10/0climage.png)

# Visual studio project version

Define a post-build to create a version file

```xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
    <Version>1.2.3</Version>
  </PropertyGroup>
  <Target Name="GetVersion" AfterTargets="PostBuildEvent">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
      <Output TaskParameter="Assemblies" ItemName="AssemblyInfo" />
    </GetAssemblyIdentity>
    <PropertyGroup>
      <VersionInfo>%(AssemblyInfo.Version)</VersionInfo>
    </PropertyGroup>
    <!--And use it after like any other variable:-->
    <Message Text="VersionInfo = $(VersionInfo)" Importance="high" />
  </Target>
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <!-- 
    <Exec Command="call $(SolutionDir)BuildScripts\PostBuild.bat $(TargetPath) $(VersionInfo)" />
    -->
    <Exec Command="echo $(VersionInfo)&gt;$(TargetDir)\version.txt" />
  </Target>
</Project>
```

# Azure



# Pipeline - building offline packages

I had trouble linking packages in the pipeline which blocked building solutions.  
The shortest path I could find, was to update configuration to look into my defined folder.  
And get a zipfile from an online resource, and extract it into this folder.

Update the configuration

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\Packages" />
    <add key="repositoryPath" value=".\Packages" />
  </config>
  <packageSources>
    [....]
```

Define your pipeline task

```
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest 'https://dl.dropboxusercontent.com/scl/fi/XXXXXXX8vl&dl=0' -OutFile '$(Build.ArtifactStagingDirectory)/NuGetPackages.zip'
- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/NuGetPackages.zip'
    destinationFolder: '.\Packages\NuGetPackages'
    cleanDestinationFolder: true
    overwriteExistingFiles: false
```

# IIS Rewrite URL - basepath

When you write a rewrite URL, and there is a subfolder, you will end up that the target application might not know how to manage the relative paths.

1\) Write in the App.razor some code to receive the BasePath

[![image.png](https://wiki.sophior.com/uploads/images/gallery/2024-12/scaled-1680-/wNCimage.png)](https://wiki.sophior.com/uploads/images/gallery/2024-12/wNCimage.png)

2\) In the rewrite rule append the basepath

[![image.png](https://wiki.sophior.com/uploads/images/gallery/2024-12/scaled-1680-/image.png)](https://wiki.sophior.com/uploads/images/gallery/2024-12/image.png)

# Get Path of MSBUILD

```xml
reg.exe query "HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0" /v MSBuildToolsPath
```

# Nuget packages: Shared library in NET9.0 SdkProject

A nuget project doesn't include a references shared library.

***(opening the Your.Client.1.0.1.nupkg should have the library in the "lib" folder)***

You can force it by modifying the cs.proj

```xml

  
  <ItemGroup>
    <Reference Include="Your.Lib.Shared">
      <HintPath>..\SecurityHoney.Lib.Shared\bin\Release\net9.0\Your.Lib.Shared.dll</HintPath>
      <Private>true</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Content Include="..\Your.Lib.Shared\bin\Release\net9.0\Your.Lib.Shared.dll">
      <Pack>true</Pack>
      <PackagePath>lib/net9.0/</PackagePath>
    </Content>
    <Content Include="..\Your.Lib.Shared\bin\Release\net9.0\Your.Lib.Shared.pdb">
      <Pack>true</Pack>
      <PackagePath>lib/net9.0/</PackagePath>
    </Content>
  </ItemGroup>
```