هل من الممكن لمشروع موقع الويب الرجوع إلى مجموعة موقعة في Visual Studio؟

StackOverflow https://stackoverflow.com/questions/5488864

سؤال

أنا أدرك الأنواع المختلفة التالية من مشاريع الويب في Visual Studio 2008:

  • مشروع موقع الويب
  • مشروع تطبيق الويب

    يمكن لمشروع تطبيق الويب الرجوع إلى تجميع موقعة طالما تم توقيع جمعية تطبيق الويب أيضا بنفس المفتاح. ومع ذلك، لا يعمل هذا مع مشروع موقع الويب لأنه لا يوجد مكان لتوقيع تجميع. أعتقد أن هذا هو أن الجمعية تجميعها ديناميكيا على الخادم؟

    على أي حال، هل من الممكن الحصول على مشروع موقع الويب يعمل مع هذه التجمع الموقع؟ أو هل يجب علي تحويل مشروع الويب هذا إلى مشروع تطبيق ويب؟

    تحرير:

    يطلب مني الموقف التالي أن أطلب التوضيح في هذا الأمر:

    لدي مكتبة فئة تتم الإشارة إليها من خلال العديد من المشاريع الأخرى في حولي في Visual Studio. أحد المشاريع هو تطبيق Windows سيتم نشره للمستخدمين الخارجيين المحددين. من أجل التأكد من أن التطبيق يستخدم التجميع الصحيح ولمنع الآخرين من استخدام الجمعية (أدرك القيود فيما يتعلق بفعاليته)، تم توقيع جميع الجمعيات ويتم الإعلان عن جميع الفصول الدراسية في المكتبة كصديق (داخلي).

    لا يبدو أن مشروع الموقع ليس له طريقة بالنسبة لي لتوقيع تجميعها وأحصل على الرسالة التالية عند محاولة استخدام أي شيء من المكتبة: "فئة غير قابلة للتقييم في هذا السياق لأنه" صديق " ، والتي ستكون متوقعة.

    السمات التالية داخل ملف assemblyinfo.vb في مشروع مكتبة الفئة: giveacodicetagpre.

    استنتاجي:

    يبدو وكأنه أنظف طريقة للقيام بذلك سيكون لتحويل موقع الويب إلى تطبيق ويب ولكن هذا سيتطلب بعض الوقت للقيام به منذ أن تم تشغيل موقعنا بالفعل وكما أشير في مناقشات أخرى، يمكن أن يكون تماما ألم يجب القيام به. المضي قدما، أعتقد أن إنشاء تطبيق ويب في المقام الأول قد يكون فكرة أفضل وأكثر مرونة للتنمية المستقبلية.

هل كانت مفيدة؟

المحلول

There's no requirement for the two projects to be signed with the same key - after all the framework assemblies are all signed with MS's key, which you don't have access to yet you can happily reference them from both Web Site and Web Application projects.

There's nothing at all stopping you referencing a signed assembly from a Website project - what errors are you seeing?


Edit to add

In light of your updated information, yes, I think you'll have to either:

  1. Convert the web site to a web application - as you rightly point out, there's no way to sign the site, and indeed, there's no real control over the libraries that ASP.NET will generate for the site.
  2. Compile two versions of the class library, one signed, the other not. You could probably use conditional compilation to achieve this.

Edit to add

I think the conditional compilation will probably end up getting messy quickly, but in brief it would work like this:

  • Open the Project Properties for the class library, and go to the Build tab.
  • Switch the "Configuration" dropdown to "All Configurations"
  • In the "Conditional compilation symbols" box, add a new symbol, such as "INTERNAL".

Go to the class libraries that you want to make public, and modify them to something like:

#if INTERNAL
  internal class MyClass
#else
  public class MyClass
#endif
  {
    [...]
  }

Then, when you need to produce the Public version of the library, remove the "INTERNAL" symbol from the properties and rebuild - you could make this easier by creating a new set of Debug and Release configurations that have this symbol defined, and switch between them using the Solution Configuration dropdown.

Potential issues:

  1. It might not be easy to tell whether you've got the symbol defined or not - I don't know what the behaviour is in vanilla VS, however with ReSharper installed it will grey out the parts of the code that won't be compiled under the current set of symbols, and flags the class as inaccessible as you type.
  2. You'll want to leave your properties and methods as public so that when you don't build it as "INTERNAL" you can access the them, but this will look a bit odd (although doesn't produce any warnings so clearly is legal).

نصائح أخرى

Now that I have a clearer picture of the issue I see that my original answer does not apply well. What I have done before in a similar situation was to use source control to branch the code files for the "Friend" classes into the consuming project so that they compile as part of the consuming assembly.

In my case I was trying to reuse some code in different server control projects without putting it into a separate dll, but I suspect it would also work well for your website scenario. It would mean your web site has no need to reference the signed DLL because the classes are compiled as part of the site and therefore all of the internal declarations should be available to it.

I don't know if this would be an option for you or not, largely depends on what source control tool you use, how you have your code repository set up, and how comfortable you are with the branching and merging concept.

Public members of a signed assembly should be available to any other project which has access to the DLL. I have created several signed assemblies and distributed them to other members of my team, we have used them in a mix of websites, web projects and console apps. The only place we ran into a conflict was when we tried to use an assembly that referenced HttpContext.Current in a console app. Even that worked if we avoided the methods which utilized this reference.

The only case in which signing/keys should be an issue is if you are trying to make them "Friends", meaning that they can see eachothers internal types and methods. The rules about friends and signing are documented here: http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top