Skip to content
Snippets Groups Projects
Commit bb1da387 authored by Bensong Liu's avatar Bensong Liu
Browse files

bug fix for previous commit, and add document

parent 951dab7c
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,7 @@ openxt sync --project-dir "~/code/Azure-Deployment-Builder" --local-repo-dir "/m ...@@ -62,7 +62,7 @@ openxt sync --project-dir "~/code/Azure-Deployment-Builder" --local-repo-dir "/m
#### 3. Use OpenXT to develop or build your project #### 3. Use OpenXT to develop or build your project
> There's outdated syntax in many csproj files, which prevents your project to build in .NET 5. > There's outdated syntax in many csproj files, which prevents your project to build in .NET 5.
> This IS NOT a OpenXT issue, read `doc/csproj-guide.md` for more detail. > This IS NOT a OpenXT issue, read [doc/csproj-compliance-net5.md](doc/csproj-compliance-net5.md) for more detail.
OpenXT currently supports bash, fish, and ~~powershell~~. You may run the following command to enable your OpenXT currently supports bash, fish, and ~~powershell~~. You may run the following command to enable your
shell session to work on CoreXT projects: shell session to work on CoreXT projects:
...@@ -70,7 +70,7 @@ shell session to work on CoreXT projects: ...@@ -70,7 +70,7 @@ shell session to work on CoreXT projects:
```bash ```bash
# bash-only # bash-only
openxt env --shell bash --project-dir "~/code/Azure-Deployment-Builder" --local-repo-dir "/mnt/hdd/CxCache" | source openxt env --shell bash --project-dir "~/code/Azure-Deployment-Builder" --local-repo-dir "/mnt/hdd/CxCache" | source
rider .../xxx.sln rider xxx.sln
``` ```
```bash ```bash
...@@ -93,8 +93,10 @@ dotnet build ...@@ -93,8 +93,10 @@ dotnet build
# FAQ # FAQ
- How do I build Control Plane with OpenXT? - How do I build ControlPlane with OpenXT?
OpenXT is not a build management tool, and we use dotnet 5.0 to build projects. OpenXT is not a build management tool, and we use dotnet 5.0 to build projects.
One software should do one thing, and there would be another tool to use `dotnet build` to build a One software should do one thing, and there would be another tool to use `dotnet build` to build a
large directory like ControlPlane. large directory like ControlPlane.
It's easier to only build the small project that you're working on.
...@@ -130,8 +130,8 @@ func GenerateCorextEnvvar(localRepoPath, buildOutputPath string, deps []dependen ...@@ -130,8 +130,8 @@ func GenerateCorextEnvvar(localRepoPath, buildOutputPath string, deps []dependen
panicErrorIfAny(err, "CreateTempFile") panicErrorIfAny(err, "CreateTempFile")
result["EnvironmentConfig"] = csprojPluginFilename result["EnvironmentConfig"] = csprojPluginFilename
result["MSBuildToolsPath"] = emptyProjectFilename result["MSBuildToolsPath"] = tmpdir // MSBuildToolsPath can not be overridden. This statement would have no effect at all.
result["ExtendedTargetsPath"] = emptyProjectFilename result["ExtendedTargetsPath"] = tmpdir
// END: Prepare temporary fake file for CoreXT imports. // END: Prepare temporary fake file for CoreXT imports.
// Set PkgXxxxx variables. // Set PkgXxxxx variables.
......
# Make your csproj compliance with .NET 5.0
.NET 5.0 is required to build .NET framework projects on Linux and MacOS, and it's also required
by OpenXT on any platform. You have to modify your csproj to be compliance with .NET 5.0.
> OpenXT would NOT solve any issue about dotNET 5.0 compliance. DO NOT create issue about this.
**This article just contains my personal opinion. It doesn't come from CloudBuild/CoreXT/dotnet official team. Use it at your own risk!**
## Common issues in existing CoreXT projects
> Fixing issues in this section has no risk to existing users.
|Rate of Error|ControlPlane|Azure-Deployment-Builder|
|---|---|---|
|Wrong Import Statement|60/1287|3/30|
|TargetFramework not set|91/217|28/28|
### Wrong Import statement
- Problem
It's required to have `<Import Project="$(ExtendedTargetsPath)\Microsoft.CSharp.targets" />` in CoreXT project.
CoreXT rely on this statement to inject extra build targets.
However, some projects are importing `$(MSBuildToolsPath)\Microsoft.CSharp.targets`. This is not necessary in
older version of dotNET, and causes double import error while using `Sdk="Microsoft.NET.Sdk"`.
- Solution
Change `$(MSBuildToolsPath)\Microsoft.CSharp.targets` to `$(ExtendedTargetsPath)\Microsoft.CSharp.targets`.
### TargetFramework not set
- Problem
> [What's the difference between TargetFrameworkVersion and TargetFramework](https://stackoverflow.com/questions/46778064/whats-the-difference-between-targetframework-and-runtimeframeworkversion)
Some projects only set `TargetFrameworkVerion` instead of `TargetFramework`.
This practice is outdated and unreliable. Although OpenXT supports it, dotNET 5.0 would fail without `TargetFramework`.
- Solution
Remove `<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>`, and add
```xml
<TargetFramework>net472</TargetFramework>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
```
## Common outdated practice in existing CoreXT projects
> Fixing issues in this section may affect existing users.
|Rate of Issue|ControlPlane|Azure-Deployment-Builder|
|---|---|---|
|Not using Microsoft.NET.Sdk|2151/2263|38/38|
|Compile Include statement|1252/2345|16/50|
### Not using Microsoft.NET.Sdk
- Problem
New dotnet projects are recommended to use `<Project Sdk="Microsoft.NET.Sdk" ...>` at the beginning of project,
but many old projects are using `<Project ToolsVersion="xx.0" ...>`. This may cause dotnet 5.0 fails to build
the project.
TODO: `DefaultTargets="Build"` may fail the build. Test if it's ok for CoreXT without this statement.
- Solution
Change `<Project ToolsVersion="xx.0" ...>` to `<Project Sdk="Microsoft.NET.Sdk" ...>`.
### Compile Include statement
All `*.cs` files under project directory are automatically included in dotnet 5.0,
and extra `<Compile Include="xxxx.cs" />` causes build failure.
- Solution
You must remove them or fail the compile.
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
// Some options here. Would be improved in beta release. // Some options here. Would be improved in beta release.
const DEDUCT_PKGNAME_FROM_VARNAME = true const DEDUCT_PKGNAME_FROM_VARNAME = true
const USE_PROJECT_NETVER_INSTEAD_OF_HINTPATH_NETVER = false const USE_PROJECT_NETVER_INSTEAD_OF_HINTPATH_NETVER = false
const OPENXT_VERSION = "0.1.3a" const OPENXT_VERSION = "1.0.0b"
func main() { func main() {
log.Println("OpenXT version " + OPENXT_VERSION) log.Println("OpenXT version " + OPENXT_VERSION)
......
...@@ -40,7 +40,7 @@ func SyncPackages(nugetConfigPath, localRepoPath string, allDeps []dependencyIte ...@@ -40,7 +40,7 @@ func SyncPackages(nugetConfigPath, localRepoPath string, allDeps []dependencyIte
// Prepare nuget local repo // Prepare nuget local repo
for _, dep := range allDeps { for _, dep := range allDeps {
log.Println("DEBUG: Downloading pkg: " + dep.pkgName + ":" + dep.targetNetVer + " as var " + dep.envName) log.Println("Downloading pkg: " + dep.pkgName + ":" + dep.targetNetVer + " as var " + dep.envName)
// Create the fake project. // Create the fake project.
err = ioutil.WriteFile(filepath.Join(fakeProjectDir, "noob.csproj"), []byte(fmt.Sprintf(fakeProjectTemplate, dep.targetNetVer)), 0666) err = ioutil.WriteFile(filepath.Join(fakeProjectDir, "noob.csproj"), []byte(fmt.Sprintf(fakeProjectTemplate, dep.targetNetVer)), 0666)
logErrorIfAny(err, "write noob.csproj for " + dep.pkgName) logErrorIfAny(err, "write noob.csproj for " + dep.pkgName)
......
...@@ -49,11 +49,6 @@ func stringToTempFile(s, pattern string) (filename string, err error) { ...@@ -49,11 +49,6 @@ func stringToTempFile(s, pattern string) (filename string, err error) {
return tmpfile.Name(), nil return tmpfile.Name(), nil
} }
func stringToFile(s, path string) (err error) {
err = ioutil.WriteFile(path, []byte(s), 0777)
return
}
func assertStringNotEmpty(s, msg string) { func assertStringNotEmpty(s, msg string) {
if s == "" { if s == "" {
panic(msg) panic(msg)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment