diff --git a/tools/csproj-to-5.go b/tools/csproj-to-5.go
index 628c06daf73bacbb28bebc905d86d781dc876efc..ce50f0a711b448aca62537ce839f07d162e444e3 100644
--- a/tools/csproj-to-5.go
+++ b/tools/csproj-to-5.go
@@ -57,7 +57,7 @@ func main() {
 	// Good luck for old MacOS! They use single \r as newline.
 	lines := strings.Split(strings.ReplaceAll(string(content), "\r\n", "\n"), "\n")
 	resultTxt := ""
-	removeEndRefInNextLine := false // temporary variable, looks like a workaround.
+	removeEndOfTagInNextLine := "" // Empty value indicates no need to remove EOT.
 	for _, line := range lines {
 		// We assume that, there's at most one issue in every line.
 		// That's why this tool only works to well-formatted csproj, instead of any xml.
@@ -65,8 +65,16 @@ func main() {
 
 		if stringContainsInsensitive(line, "<compile include=") {
 			if ! strings.Contains(line, "..") {
-				// Remove this line
-				continue
+				// Remove this <compile include>!
+				if strings.Contains(line, "/>") {
+					// Just remove this line
+					continue
+				} else {
+					// Remove until tag close
+					if removeEndOfTagInNextLine == "" {
+						removeEndOfTagInNextLine = "</compile>"
+					}
+				}
 			}
 		}
 
@@ -99,18 +107,23 @@ func main() {
 
 		if stringContainsInsensitive(line, `"System.ValueTuple"`) || stringContainsInsensitive(line, `$(PkgSystem_ValueTuple)`) {
 			// Remove this line.
-			removeEndRefInNextLine = ! stringContainsInsensitive(line, "</Reference>")
+			if ! stringContainsInsensitive(line, "</Reference>") {
+				// We need to remove more lines...
+				if removeEndOfTagInNextLine == "" {
+					removeEndOfTagInNextLine = "</Reference>"
+				}
+			}
 			continue;
 		}
-		if removeEndRefInNextLine {
-			pos := stringIndexInsensitive(line, "</Reference>");
+		if removeEndOfTagInNextLine != "" {
+			pos := stringIndexInsensitive(line, removeEndOfTagInNextLine);
 			if pos == -1 {
 				// this line still not contains </Reference>
 				// Skip this line and keep checking next line.
 				continue
 	 		} else {
-				line = line[pos+len("</Reference>"):]
-				removeEndRefInNextLine = false
+				line = line[pos+len(removeEndOfTagInNextLine):]
+				removeEndOfTagInNextLine = ""
 			}
 		}