简体   繁体   中英

How to create a Hash Code from Source Code in C#?

The problem:

I am trying to create a function that creates a hash code of the source code of my asp.net web application backend.

As long as nothing gets changed, this hash code needs to be identical. Even if I rebuild my project.

Does someone know, how I can do that?

What I tried:

The only working solution I found is to concat all important files to a big string and create a hash code out of it.

The problem of this solution is, that I have to add all the source files to the output directory, what shouldn't be done for security reasons.

Hope someone has a great idea =)

Thanks in advance!

Update:

I could solve my problem by enabling deterministic build as Renat suggested.

Just added the deterministic flag to my .csproj file as follows:

<Deterministic>True</Deterministic>

Even if I rebuild my project

You may use Deterministic Build , then it will produce the same binaries in each build being made out of same source codes. Then you may get the hash of binaries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM