标题:C#,使用vs 2015, 我想把各个项目都要用到的相同的类都放在一个共用.cs文件里 ...
只看楼主
瓯旸臻骅
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2021-3-10
结帖率:0
 问题点数:0 回复次数:1 
C#,使用vs 2015, 我想把各个项目都要用到的相同的类都放在一个共用.cs文件里集中管理,更新升级都能使用,该怎么做呢?
RT!
求指教
搜索更多相关主题的帖子: 升级 管理 相同 文件 更新 
2021-03-10 16:34
qq2889577966
Rank: 4
等 级:业余侠客
威 望:5
帖 子:57
专家分:267
注 册:2021-4-14
得分:0 
使用动态编译
比如
程序代码:
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
                string Output = "~Setup.exe";
                CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add(@"System.dll");
                parameters.ReferencedAssemblies.Add(@"System.Windows.dll");
                parameters.ReferencedAssemblies.Add(@"System.Windows.Forms.dll");
                parameters.ReferencedAssemblies.Add(@"System.Xaml.dll");
                parameters.ReferencedAssemblies.Add(@"System.Xml.dll");
                parameters.ReferencedAssemblies.Add(@"System.Drawing.dll");
                parameters.ReferencedAssemblies.Add(@"WPFSystem.Windows.Presentation.dll");
                parameters.ReferencedAssemblies.Add(@"WPFPresentationCore.dll");
                parameters.ReferencedAssemblies.Add(@"WPFPresentationFramework.dll");
                parameters.ReferencedAssemblies.Add(@"WPFWindowsBase.dll");
                parameters.EmbeddedResources.Add("setup_res.resources");

                parameters.GenerateExecutable = true;
                 = " -t:winexe";
                parameters.OutputAssembly = Output;

                CompilerResults results = (
                    parameters, 你的cs文件
                    );


比如建立一个wpf的以管理员运行的cs文件的字符串 code= @"下面的字符串"
程序代码:
string code = @"using System;
using System.Xml;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Documents;
using System.Resources;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using   System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Markup;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Reflection;
using System.Diagnostics;
using System.Security.Principal;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Threading;
using System.Runtime.Serialization.Formatters.Binary;
using  partial class App:System.Windows.Application
{
    [STAThread]    
    public static void Main()
    {
        WindowsIdentity identity = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(identity);
                    
        if (principal.IsInRole(WindowsBuiltInRole.Administrator))
        {
            App app=new App();
            app.Run();
        }
        else
        {
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.WorkingDirectory = Environment.CurrentDirectory;
            startInfo.FileName = Assembly.GetExecutingAssembly().Location;
            startInfo.Verb = ""runas"";
            try
            {
                System.Diagnostics.Process.Start(startInfo);
            }
            catch
            {
                return;
            }
            System.Windows.Application.Current.Shutdown();
        }
    }

static Grid grid; 
    static Window w;
    static Canvas mainBox;

protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        w=new Window();
        w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        w.WindowStyle = WindowStyle.None;
        w.AllowsTransparency = true;
        w.Background = null;
        w.Width = 783;
        w.Height = 485;
        grid=new Grid();
        w.Content = grid;
        mainBox = new Canvas() { Width=783, Height=485,};
        grid.Children.Add(mainBox);
        w.Topmost = true;

        
        w.Show();
    }

2021-04-15 11:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505071-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054381 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved