因为最近在写cobaltstrike的execute-assembly内存加载的c#项目
 用visual studio2022编译,最低net只能用6.0版本的,并且execute-assembly不支持
 
 我想使用4.x版本进行编译,因为visual studio不支持,那么使用命令行进行编译
 因为要用到MSBuild.exe,我直接选择低版本的
 
 用x64或者另一个都可以,只要ConsoleApp2.csproj写上对应属性就好
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <!-- .NET Framework 4.8 -->
    <PlatformTarget>x64</PlatformTarget> <!-- 目标处理器架构设置为 x64 -->
    <RootNamespace>ConsoleApp2</RootNamespace>
    <AssemblyName>ConsoleApp2</AssemblyName>
	<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration> <!-- 默认配置为 Release -->
    <Platform Condition=" '$(Platform)' == '' ">x64</Platform> <!-- 默认平台为 x64 -->
    <OutputPath>bin\$(Configuration)\</OutputPath> <!-- 输出路径 -->
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <!-- 添加其他引用 -->
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <!-- 添加其他源文件 -->
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
我的项目代码为
using System;
namespace HelloWorldApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string name;
            if (args.Length > 0)
            {
                name = args[0];
                Console.WriteLine($"你好, {name}!");
            }
            else
            {
                Console.WriteLine("没有提供命令行参数。请输入您的名字:");
                
            }    
        }
    }
}
但是编译会报错
 
说明字符串插值不能使用 
     
      
       
       
         , 
        
       
      
        , 
       
      
    ,是在 C# 6.0 引入的,而 .NET Framework 4.0 默认使用的 C# 编译器版本是 4.0,它不支持这些特性
 所以需要改成+拼接参数,如下
using System;
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 检查是否传入了命令行参数
            if (args.Length > 0)
            {
                // 如果传入了参数,使用第一个参数
                string name = args[0];
                Console.WriteLine("Hello, " + name + "!");
            }
            else
            {
                // 如果没有传入参数,使用默认值
                string defaultName = "world";
                Console.WriteLine("Hello, " + defaultName + "!");
            }
        }
    }
}
这样就可以成功生成了
 
 在cobaltstrike中试试效果
 
 可以看到成功达到效果,那么接下来看看完成一些功能
 https://github.com/breakid/SharpUtils有一些功能,我来试试env的
 
 可以看到成功显示出来env
















![[单master节点k8s部署]24.构建EFK日志收集平台(三)](https://i-blog.csdnimg.cn/direct/eb32ace4b7ca44dd8797546bb25dcd58.png)


