C#在编译时将日期放入程序 [英] C# put date into program when compiled

查看:53
本文介绍了C#在编译时将日期放入程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在考虑如何创建一个仅在X时段内有效的程序(在C#应用程序中).

I was thinking about how to create a program that would only be valid for X period of time, (within a C# app).

我在想的是,您会将程序中的当前日期作为一个常量,它将检查是否比该日期早X天.自然,我不想存储日期或程序外部的X,因为它可能会被篡改.

What I was thinking was that you would have the current date as a constant inside the program and it would check to see if it is X days older than that. Naturally I do not want to store the date, or the X outside of the program as it can be tampered with.

我也不想定期手动更改它,然后重新编译和部署它.那么有没有办法将变量设置为编译时的当前日期?

What I also do not want to manually change this regularly and recompile and deploy it. So is there a way to set a variable to be the current date when it is compiled?

我可以有一个可以对其进行编译并将新exe部署到分发服务器的批处理文件.

I could have a batch file that would compile it and deploy the new exe to the distribution server.

谢谢

推荐答案

预编译指令是您的关键.您可以在应用程序中创建一个常量,并在编译时对其进行设置.

Precompilation directives are your key here. You could create a constant in your application and have it set when you compile.

但是,请确保对代码进行混淆.有人可以轻松拆卸它并篡改常量.另一个解决方案是让您的软件电话回家"进行注册.这样,注册信息将存储在您的服务器上,而不是它们的计算机上.也有第三方程序包具有与您所寻找的相同的安全性,但它们价格昂贵

Make sure you obfuscate your code, however. Someone could disassemble it easily and tamper with the constant. Another solution is to have your software "phone home" to register itself. That way, the registration info is stored on your server and not their machine. There are also third party packages that perform the same security as you're looking for, but they are expensive!

这篇关于C#在编译时将日期放入程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆